home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / CAD / AC2VIV.ARJ / AC2VIV.LSP < prev    next >
Lisp/Scheme  |  1992-04-13  |  95KB  |  4,974 lines

  1. ;;  AC2VIV 1.0
  2. ;;
  3. ;;  AutoCAD R11 to VIVID 2.0 translator 
  4. ;;
  5. ;;  Copyright 1991, 1992 Roy Hirshkowitz, all rights reserved.
  6. ;;
  7. ;;  Autocad and Autolisp are registered trademarks of Autodesk,Inc.
  8. ;;  Vivid 2.0 is Copyright Stephen B. Coy, Vivid Software
  9. ;;
  10.  
  11. (princ "\nLoading Autocad to Vivid translator\n")
  12.  
  13.  
  14. (regapp "VIVID_RJH")        ;register extended entity app
  15. (princ ".")
  16. (defun c:ac2viv ()
  17.  
  18. ;*************************************************************
  19. ;*                                
  20. ;*  initialization-  open files, initialize variables         
  21. ;*                        
  22. ;**************************************************************
  23.  
  24.  
  25.  
  26.     
  27.  
  28.     (setq temp (strcat (getstring "Output file:  " ) ".v"))
  29.  
  30.     (while    (not (setq vivid_in (open temp "w")))
  31.         (princ (strcat "\nCannot open file " temp))
  32.         (setq temp (strcat (getstring "\nOutput file:  " ) ".v"))
  33.     )
  34.  
  35.     (textscr)
  36.  
  37.     (princ "\n3d Entities Translated:\n")
  38.  
  39.     (setq v_studio_list nil)
  40.  
  41.     (setq start_time (getvar "date"))
  42.  
  43. ;;DEBUGGING COUNTERS
  44.  
  45.     (SETQ CTR1 0.0)
  46.     (SETQ CTR2 0.0)
  47.     (SETQ CTR3 0.0)
  48.     (SETQ CTR4 0.0)
  49.     (SETQ CTR5 0.0)
  50.  
  51.  
  52. ;; initialize counters used for statistical reporting
  53.  
  54.     (setq main_count 0)        ;3d drawing entity counter
  55.     (setq 3dface_count 0)        ;3dfaces and
  56.     (setq 3dface_p_count 0)        ;   # of resulting VIVID polygons
  57.     (setq line_count 0)        ;extruded lines
  58.     (setq 2dpoly_count 0)        ;extruded 2d polylines and
  59.     (setq 2dpoly_p_count 0)        ;   # of resulting VIVID polygons
  60.     (setq 2dpoly_r_count 0)        ;   # of resulting VIVID rings
  61.     (setq 2dpoly_c_count 0)        ;   # of resulting VIVID cones
  62.     (setq circle_count 0)        ;extruded circles & V_CONE?? blocks
  63.     (setq arc_count 0)        ;extruded arcs and
  64.     (setq arc_c_count 0)        ;   # of resulting VIVID cones
  65.     (setq solid_count 0)        ;solids and
  66.     (setq solid_p_count 0)        ;   # of resulting VIVID polygons
  67.     (setq sphere_count 0)        ;v_sphere blocks (unit spheres)
  68.     (setq disk_count 0)        ;v_disk blocks (unit rings)
  69.  
  70.     ;* smoothed meshes
  71.     (setq 3dmesh_count 0)        ;# of 3d meshes and
  72.     (setq 3dmesh_p_count 0)        ;  # of resulting VIVID patches
  73.     (setq pface_count 0)        ;polyface meshes and
  74.     (setq pface_p_count 0)        ;   # of resulting VIVID patches
  75.  
  76.     ;* faceted meshes
  77.     (setq f_3dmesh_count 0)        ;# of 3d meshes and
  78.     (setq f_3dmesh_p_count 0)         ;  # of resulting VIVID polygons
  79.     (setq f_pface_count 0)        ;polyface meshes and
  80.     (setq f_pface_p_count 0)          ;   # of resulting VIVID polygons
  81.  
  82.  
  83.     (setq light_count 0)        ;# of lights
  84.  
  85.  
  86.  
  87.  
  88.         
  89. ; build "master" list using layer table
  90. ;    
  91.     (setq temp (tblnext "Layer" t))
  92.     (setq master (list))
  93.     (setq test1 1)
  94.     (while temp
  95.         (if    (= (boole 1 (cdr (assoc 70 temp)) test1) 0)
  96.  
  97.             (setq master (cons (list (cdr (assoc 2 temp)) (list " ")) master))
  98.         )
  99.         (setq temp (tblnext "Layer"))
  100.     )
  101.  
  102.  
  103. ;;
  104. ;; start light list 
  105. ;;
  106.  
  107.     (setq v_lights (list " "))
  108.  
  109. ;***********************************************************************
  110. ;*  end of initialization phase
  111. ;************************************************************************
  112.  
  113. ;************************************************************
  114. ;*
  115. ;*    Construction phase-- build tables (lists) using geometric info. from drawing
  116. ;*
  117. ;**************************************************************************    
  118.  
  119.  
  120.  
  121.  
  122.     (v_main 0 (entnext) nil 1 nil nil)
  123.  
  124.  
  125. ;********************************************************************
  126. ;*        End of construction phase
  127. ;********************************************************************
  128.  
  129. ;***************************************************************
  130. ;*
  131. ;*        Extraction phase-- write data to output file
  132. ;*
  133. ;****************************************************************
  134.  
  135.     (princ "\nWriting information to output file.")
  136.  
  137.  
  138. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  139. ;;
  140. ;;  extract studio information-- use default value if none found
  141. ;;
  142. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  143.  
  144. ;; studio
  145.  
  146.     (write-line "#include color.vc" vivid_in)
  147.     (write-line "studio = {" vivid_in)
  148.     (setq pt1 (trans (getvar "target") 1 0))
  149.     (setq pt2 (mapcar '+ pt1 (trans (getvar "viewdir") 1 0 T)))
  150.     (write-line
  151.         (strcat
  152.         "at "
  153.         (rtos (car pt1) 2 6)
  154.         " "
  155.         (rtos (cadr pt1) 2 6)
  156.         " "
  157.         (rtos (caddr pt1) 2 6)
  158.         " "
  159.         )
  160.     vivid_in
  161.     )
  162.  
  163.             
  164.     (write-line
  165.         (strcat
  166.         "from "
  167.         (rtos (car pt2) 2 6)
  168.         " "
  169.         (rtos (cadr pt2) 2 6)
  170.         " "
  171.         (rtos (caddr pt2) 2 6)
  172.         " "
  173.         )
  174.     vivid_in
  175.     )
  176.  
  177. ;; derive field of view from lenslength (angle = 50/lenslength * 35)
  178.  
  179.     (write-line
  180.         (strcat
  181.         "angle ="
  182.         (rtos (* (/ 50.00 (getvar "lenslength")) 35) 2 2) 
  183.         " "
  184.         )
  185.     vivid_in
  186.     )
  187.     
  188.  
  189. ;; see if v_studio block was found in drawing-- if not use defaults
  190.  
  191.     (if    (not v_studio_list)
  192.  
  193.         (progn
  194.         (write-line "up = 0 0 1;" vivid_in)
  195.         (write-line "resolution = 1024 768;" vivid_in)
  196.         (write-line "aspect = 1.3333;" vivid_in)
  197.         (write-line "ambient = .2 .2 .2;" vivid_in)
  198.         (write-line "background = sky_blue;" vivid_in)
  199.         (write-line "antialias = adaptive;" vivid_in)
  200.         (write-line "depth=4" vivid_in)
  201.         )
  202.  
  203.         (foreach n v_studio_list (write-line n vivid_in))
  204.     )
  205.     (write-line "}" vivid_in)
  206.  
  207. ;:::::::::::::::::::::::::::::::::::::::::::
  208. ;; extract information for "light" structures
  209.  
  210.  
  211.     (foreach n (reverse v_lights) (write-line n vivid_in))
  212.  
  213. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  214. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
  215. ;; extract information from master list and write to file
  216.  
  217.     (setq temp master)
  218.     (setq temp1 (car master))
  219.     
  220.     
  221.  
  222.     (while temp1
  223.         (if    (cdadr temp1) 
  224.             (progn
  225.                 (write-line (strcat
  226.                         "#include "
  227.                         (car temp1)
  228.                         ".vs"
  229.                          )
  230.                          vivid_in
  231.                 )
  232.                 (foreach n (car (cdr temp1)) (write-line n vivid_in))
  233.             )
  234.         )
  235.         (setq temp (cdr temp))
  236.         (setq temp1 (car temp))        
  237.             
  238.     )
  239.  
  240.  
  241. ;; print statistical stuff
  242.  
  243.     (princ "\n")
  244.     (prin1 3dface_count)
  245.     (princ " 3dfaces to ")
  246.     (prin1 3dface_p_count)
  247.     (princ " VIVID polygons")
  248.     (princ "\n")
  249.     (prin1 line_count)
  250.     (princ " extruded lines to VIVID polygons")
  251.     (princ "\n")
  252.     (prin1 2dpoly_count)
  253.     (princ " 2dPolylines to ")
  254.     (prin1 2dpoly_p_count)
  255.     (princ " VIVID polygons, ")
  256.     (prin1 2dpoly_r_count)
  257.     (princ " rings and ")
  258.     (prin1 2dpoly_c_count)
  259.     (princ " cones")
  260.     (princ "\n")
  261.     (prin1 circle_count)
  262.     (princ " extruded circles & V_Cone blocks to VIVID cones")
  263.     (princ "\n")
  264.     (prin1 arc_count)
  265.     (princ " extruded arcs to ")
  266.     (prin1 arc_c_count)
  267.     (princ " VIVID cones")
  268.         (princ "\n")
  269.     (prin1 solid_count)
  270.     (princ " solids to ")
  271.     (prin1 solid_p_count)
  272.     (princ " VIVID polygons")
  273.     (princ "\n")
  274.     (prin1 sphere_count)
  275.     (princ " V_Sphere blocks to VIVID spheres")
  276.         (princ "\n")
  277.     (prin1 disk_count)
  278.     (princ " V_Disk blocks to VIVID rings")
  279.  
  280.  
  281.         (princ "\n")
  282.     (prin1 3dmesh_count)
  283.     (princ " 3dmeshes to ")
  284.     (prin1 3dmesh_p_count)
  285.     (princ " VIVID patches")
  286.     (princ "\n")
  287.     (prin1 pface_count)
  288.     (princ " polyface meshes to ")
  289.     (prin1 pface_p_count)
  290.     (princ " VIVID patches")
  291.  
  292.         (princ "\n")
  293.     (prin1 f_3dmesh_count)
  294.     (princ " 3dmeshes to ")
  295.     (prin1 f_3dmesh_p_count)
  296.     (princ " VIVID polygons")
  297.     (princ "\n")
  298.     (prin1 f_pface_count)
  299.     (princ " polyface meshes to ")
  300.     (prin1 f_pface_p_count)
  301.     (princ " VIVID polygons")
  302.  
  303.  
  304.  
  305.     (princ "\n")
  306.     (prin1 light_count)
  307.     (princ " light sources")
  308.  
  309.  
  310.  
  311.  
  312.  
  313.     (close vivid_in)
  314.  
  315. ;; calculate and display translation time.
  316.     
  317.     (setq end_time (getvar "date"))
  318.     (setq seconds (* 86400.0 (- end_time start_time)))
  319.     (setq minutes (fix (/ seconds 60.0) ))
  320.     (setq seconds (fix (+ (rem seconds 60.0) 0.5)))
  321.     (princ "\n")
  322.     (princ "Translation time: ")
  323.     (prin1 minutes)
  324.     (princ " minutes, ")
  325.     (prin1 seconds)
  326.     (princ " seconds.")
  327.     (princ)
  328.  
  329. )
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346. ;***********************************************************************
  347. ;*  END OF C:VIVID-- SUBROUTINES FOLLOW
  348. ;***********************************************************************
  349.  
  350.  
  351. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  352. ;;
  353. ;;    MAIN ROUTINE -- do single pass through entities extracting info.
  354. ;;     and placing it in correct data structure for subsequent processing.
  355. ;;    Primary data structure for geometric data is called "master" and consists
  356. ;;    of a list whose elements are lists whose first elements are layer names
  357. ;;    and second element is a list of strings (geometric data) to be output
  358. ;;    to VIVID.  Other data structures built by this routine include 
  359. ;;    a list of lights and a studios.
  360. ;;
  361. ;;    Parameters--
  362. ;;
  363. ;;        e -- ename of startin entity in list
  364. ;;        b_flag -- nesting count (for processing blocks)
  365. ;;        trans_matrix -- MCS to WCS transform (for processing blocks, this is
  366. ;;                            "nil" if processing main entities.)
  367. ;;        s_factor -- cumulative scale factor maintained for processing blocks
  368. ;;                (This is useful for things like circle radii-- note that
  369. ;;                 it is strictly the "x" scale factor.
  370. ;;
  371. ;;        block_smooth -- T if all meshes within this block are to be
  372. ;;                translated to patches rather than polygons.
  373. ;;                Flag is set independently for nested blocks.
  374. ;;
  375. ;;        block_layer --     contains layer name of block if this is a
  376. ;;                block, nil otherwise.  Used in place of layer
  377. ;;                "0" for entities within blocks.
  378. ;;        
  379. ;;
  380. ;;    In order to process blocks and nested blocks this routine is called
  381. ;;    recursively.  If it is being called to process block entities it is
  382. ;;    called with the b_flag parameter set to 1 or greater.  This is necessary because
  383. ;;    coordinates of block entities need to be further translated according
  384. ;;    to position and scale of the particular insertion. (MCS to WCS transform)
  385. ;;
  386. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  387.  
  388.  
  389. (princ ".")
  390. (defun v_main (b_flag e trans_matrix s_factor block_smooth block_layer)
  391.         
  392.         
  393.     (while e
  394.         
  395.         (setq s (entget e (list "VIVID_RJH")))
  396.         
  397.         (cond
  398.  
  399. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  400. ;; 3dface
  401. ;;    Since four points of face are not necessarily coplanar-- split
  402. ;;    into triangles if necessary.
  403. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  404.  
  405.  
  406.             (
  407.             (and (= (cdr (assoc 0 s)) "3DFACE")
  408.                  (check_layer block_layer)
  409.             )
  410.  
  411.             (progn
  412.  
  413.                 (print_count)
  414.                 (setq 3dface_count (1+ 3dface_count))
  415.                 (setq 3dface_p_count (1+ 3dface_p_count))
  416.  
  417.                 (setq a (cdr (assoc 10 s)))
  418.                 (setq b (cdr (assoc 11 s)))
  419.                 (setq c (cdr (assoc 12 s)))
  420.                 (setq d (cdr (assoc 13 s)))
  421.  
  422.  
  423.                 (if     (not (equal (cdr (assoc 13 s)) (cdr (assoc 12 s))))
  424.  
  425.                     ;check to see if points are coplanar
  426.  
  427.                     (if    (inters a c b d T)
  428.                         (draw_4 a b c d trans_matrix)
  429.                         (progn
  430.                             (draw_3 a b c trans_matrix)
  431.                             (draw_3 a c d trans_matrix)
  432.                             (setq 3dface_p_count (1+ 3dface_p_count))
  433.                         )
  434.                     )
  435.  
  436.                     (draw_3 a b c trans_matrix)
  437.                 )
  438.             
  439.             )
  440.             )
  441.  
  442.             
  443. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  444. ;; extruded line
  445. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  446.  
  447.             (
  448.             (and     (= (cdr (assoc 0 s)) "LINE") 
  449.                 (check_layer block_layer)
  450.                 (and
  451.                     (assoc 39 s)
  452.                     (/= (cdr (assoc 39 s)) 0)
  453.                 )
  454.             )
  455.  
  456.             (progn
  457.  
  458.                 (print_count)
  459.                 (setq line_count (1+ line_count))
  460.                 
  461.                 ;  multiply thickness by extrusion vector
  462.                 ;  and add to coordinates to obtain 3rd and 4th
  463.                 ;  vertices of polygons
  464.  
  465.                 (setq a (cdr (assoc 10 s)))
  466.                 (setq b (cdr (assoc 11 s)))
  467.                 (setq ee (cdr (assoc 210 s)))
  468.                 (setq ee  (mapcar '(lambda (x)
  469.                          (* x (cdr (assoc 39 s)))
  470.                          )
  471.                           ee
  472.                       )
  473.                 )
  474.                 (setq c (mapcar '+ b ee))
  475.                 (setq d (mapcar '+ a ee))
  476.  
  477.                 (draw_4 a b c d trans_matrix)
  478.                 
  479.                 
  480.             ) ; close progn
  481.  
  482.             )
  483.  
  484.  
  485. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  486. ;;
  487. ;; extruded simple 2-d polylines -- not 3dmeshes 
  488. ;;
  489. ;;  routine has a complex organization because of the complexity of
  490. ;;  the 2-d polyline entity.  The entity can contain "wide" segments,
  491. ;;  which need to be drawn whether or not the polyline is extruded.  It
  492. ;;  also can contain arcs, which can either be wide or skinny, extruded
  493. ;;  or not extruded.
  494. ;;
  495. ;;  At this time curve or spline fit polylines are not supported.  Also
  496. ;;  polyline arcs with variable widths will be translated to constant width
  497. ;;  arcs (the starting width will be used).  This particular item will be
  498. ;;  corrected as soon as I can figure out how to do it with VIVID prims.
  499. ;;
  500. ;;  All 2dpolys are pre-processed first.  A segment list is built which
  501. ;;  expands wide segments into four vertices.  If we have encountered wide
  502. ;;  segments, or if this polyline is thick (extruded), than it needs to be
  503. ;;  drawn.
  504. ;;
  505. ;;  The routine draw_poly then steps through this segment list.  If one fat
  506. ;;  (wide) segment is followed by another, and the angle which they define
  507. ;;  differs from 180 degrees by some fixed tolerance, then the endpoints of
  508. ;;  each fat segment are redefined.  This should produce a result identical
  509. ;;  to the way AutoCAD handles wide polys.  Because of this, the first segment
  510. ;;  of a closed polyline needs to be treated differently.
  511. ;;
  512. ;;  Draw_poly calls draw_arc, draw_fat, or draw_skinny, depending on the segment
  513. ;;  encountered.
  514. ;;
  515. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  516.  
  517.             (
  518.             (and     (= (cdr (assoc 0 s)) "POLYLINE") 
  519.                 (check_layer block_layer)
  520.                 (=  0 (boole 1 126 (cdr (assoc 70 s))))  ;2-d only -- 
  521.                                      ;no splines or curves
  522.             )
  523.  
  524.  
  525.             
  526.             (setq draw_this_poly? nil)
  527.  
  528.             ; * if polyline is thick (extruded) we definitely need
  529.             ; * to draw it
  530.  
  531.             (if    (setq save_thickness (cdr (assoc 39 s)))
  532.                 (setq draw_this_poly? T)
  533.             )
  534.  
  535.  
  536.  
  537.  
  538.             (pre_process_poly)
  539.  
  540.             (if    draw_this_poly?
  541.  
  542.  
  543.                 (progn
  544.  
  545.                     (print_count)
  546.                     (setq 2dpoly_count (1+ 2dpoly_count))
  547.                     (draw_poly trans_matrix)
  548.                     
  549.                 )
  550.  
  551.             ) ; close if
  552.  
  553.             ) ; close cond clause
  554.             
  555.                             
  556. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  557. ;;
  558. ;;    solids-- may be extruded or flat.
  559. ;;
  560. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  561.  
  562.             (
  563.             (and     (= (cdr (assoc 0 s)) "SOLID")
  564.                      (check_layer block_layer)
  565.             )
  566.  
  567.             (print_count)
  568.             (setq solid_count (1+ solid_count))
  569.  
  570.             (setq     a (cdr (assoc 10 s))
  571.                 b (cdr (assoc 11 s))
  572.                 c (cdr (assoc 12 s))
  573.                 d (cdr (assoc 13 s))
  574.             )
  575.  
  576.  
  577.             (if    (and    (assoc 39 s)
  578.                     (/= 0 (cdr (assoc 39 s)))
  579.                 )
  580.  
  581.                 (setq ee 
  582.                         (list
  583.                         0.0
  584.                         0.0
  585.                         (cdr (assoc 39 s))
  586.                         )
  587.                 )
  588.  
  589.                 (setq ee nil)
  590.             )
  591.  
  592.  
  593.             
  594.  
  595.             (if    (equal c d)
  596.                 
  597.                 ;* triangular solid
  598.  
  599.                 (if    ee
  600.  
  601.                     ;* triangular prism
  602.                     (progn
  603.  
  604.                     (setq a1 (trans (mapcar '+ a ee) (cdr (assoc 210 s)) 0 ))
  605.                     (setq b1 (trans (mapcar '+ b ee) (cdr (assoc 210 s)) 0 ))
  606.                     (setq c1 (trans (mapcar '+ c ee) (cdr (assoc 210 s)) 0 ))
  607.  
  608.                     (setq a (trans a (cdr (assoc 210 s)) 0))
  609.                     (setq b (trans b (cdr (assoc 210 s)) 0))
  610.                     (setq c (trans c (cdr (assoc 210 s)) 0))
  611.  
  612.  
  613.                     (draw_3 a b c trans_matrix)
  614.                     (draw_3 a1 b1 c1 trans_matrix)
  615.                     (draw_4 a b b1 a1 trans_matrix)
  616.                     (draw_4 b c c1 b1 trans_matrix)
  617.                     (draw_4 c a a1 c1 trans_matrix)
  618.  
  619.                     (setq solid_p_count (+ 5 solid_p_count))
  620.  
  621.                     )
  622.  
  623.  
  624.                     ;* triangular face 
  625.                     (progn
  626.                         
  627.                     (setq a (trans a (cdr (assoc 210 s)) 0))
  628.                     (setq b (trans b (cdr (assoc 210 s)) 0))
  629.                     (setq c (trans c (cdr (assoc 210 s)) 0))
  630.  
  631.                     (draw_3 a b c trans_matrix)
  632.                     (setq solid_p_count (1+ solid_p_count))
  633.  
  634.                     )
  635.  
  636.                 ) ; close if
  637.  
  638.  
  639.  
  640.  
  641.                 (if    (setq f (inters a c b d T))
  642.  
  643.                     ;*  bowtie here
  644.         
  645.                     (if    ee
  646.  
  647.                         ;* bowtie prism
  648.                         (progn
  649.  
  650.                         (setq a1 (trans (mapcar '+ a ee) (cdr (assoc 210 s)) 0 ))
  651.                         (setq b1 (trans (mapcar '+ b ee) (cdr (assoc 210 s)) 0 ))
  652.                         (setq c1 (trans (mapcar '+ c ee) (cdr (assoc 210 s)) 0 ))
  653.                         (setq d1 (trans (mapcar '+ d ee) (cdr (assoc 210 s)) 0 ))
  654.                         (setq f1 (trans (mapcar '+ f ee) (cdr (assoc 210 s)) 0 ))
  655.                     
  656.                         
  657.                             
  658.                         (setq a (trans a (cdr (assoc 210 s)) 0))
  659.                         (setq b (trans b (cdr (assoc 210 s)) 0))
  660.                         (setq c (trans c (cdr (assoc 210 s)) 0))
  661.                         (setq d (trans d (cdr (assoc 210 s)) 0))
  662.                         (setq f (trans f (cdr (assoc 210 s)) 0))
  663.                         
  664.  
  665.                         (draw_3 a b f trans_matrix)
  666.                         (draw_3 a1 b1 f1 trans_matrix)
  667.                         (draw_3 d c f trans_matrix)
  668.                         (draw_3 d1 c1 f1 trans_matrix)
  669.  
  670.                         (draw_4 a b b1 a1 trans_matrix)
  671.                         (draw_4 b d d1 b1 trans_matrix)
  672.                         (draw_4 a c c1 a1 trans_matrix)
  673.                         (draw_4 c d d1 c1 trans_matrix)
  674.             
  675.                 
  676.                     
  677.                         (setq solid_p_count (+ 8 solid_p_count))
  678.     
  679.                         )
  680.             
  681.                 
  682.                         ;* bowtie face 
  683.                         (progn
  684.                             
  685.                         (setq a (trans a (cdr (assoc 210 s)) 0))
  686.                         (setq b (trans b (cdr (assoc 210 s)) 0))
  687.                         (setq c (trans c (cdr (assoc 210 s)) 0))
  688.                         (setq d (trans d (cdr (assoc 210 s)) 0))
  689.                         (setq f (trans f (cdr (assoc 210 s)) 0))
  690.  
  691.                         (draw_3 a b f trans_matrix)
  692.                         (draw_3 f d c trans_matrix)
  693.                         (setq solid_p_count (+ 2 solid_p_count))
  694.                 
  695.                         )
  696.                         
  697.                     ) ; close if
  698.  
  699.  
  700.                 ;* four sided here
  701.  
  702.  
  703.                 (if    ee
  704.  
  705.                     ;* four-sided prism
  706.                     (progn
  707.  
  708.                     (setq a1 (trans (mapcar '+ a ee) (cdr (assoc 210 s)) 0 ))
  709.                     (setq b1 (trans (mapcar '+ b ee) (cdr (assoc 210 s)) 0 ))
  710.                     (setq c1 (trans (mapcar '+ c ee) (cdr (assoc 210 s)) 0 ))
  711.                     (setq d1 (trans (mapcar '+ d ee) (cdr (assoc 210 s)) 0 ))
  712.  
  713.  
  714.                     (setq a (trans a (cdr (assoc 210 s)) 0))
  715.                     (setq b (trans b (cdr (assoc 210 s)) 0))
  716.                     (setq c (trans c (cdr (assoc 210 s)) 0))
  717.                     (setq d (trans d (cdr (assoc 210 s)) 0))
  718.         
  719.                     (draw_4 a b d c trans_matrix)
  720.                     (draw_4 a1 b1 d1 c1 trans_matrix)
  721.                     (draw_4 a b b1 a1 trans_matrix)
  722.                     (draw_4 b d d1 b1 trans_matrix)
  723.                     (draw_4 d c c1 d1 trans_matrix)
  724.                     (draw_4 c a a1 c1 trans_matrix)
  725.  
  726.                     (setq solid_p_count (+ 6 solid_p_count))
  727.  
  728.                     )
  729.  
  730.  
  731.                     ;* four-sided face 
  732.                     (progn
  733.                     
  734.                     (setq a (trans a (cdr (assoc 210 s)) 0))
  735.                     (setq b (trans b (cdr (assoc 210 s)) 0))
  736.                     (setq c (trans c (cdr (assoc 210 s)) 0))
  737.                     (setq d (trans d (cdr (assoc 210 s)) 0))
  738.  
  739.                     (draw_4 a b d c trans_matrix)
  740.                     (setq solid_p_count (1+ solid_p_count))
  741.  
  742.                     )
  743.  
  744.  
  745.  
  746.                 ) ; close if
  747.  
  748.             ) ;close if bowtie
  749.             
  750.             ) ;close if triangular
  751.  
  752.  
  753.             ) ;close cond clause
  754.  
  755.                 
  756.  
  757. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  758. ;;
  759. ;;    extruded arcs-- convert to VIVID cones w/ clipping planes
  760. ;;
  761. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  762.  
  763.  
  764.  
  765.  
  766.  
  767.             (
  768.  
  769.             (and     (= (cdr (assoc 0 s)) "ARC") 
  770.                 (check_layer block_layer)
  771.                 (and
  772.                     (assoc 39 s)
  773.                     (/= (cdr (assoc 39 s)) 0)
  774.                 )
  775.             )
  776.  
  777.  
  778.             (print_count)
  779.             (setq arc_count (1+ arc_count))            
  780.  
  781.  
  782.  
  783.             (setq arc_center (cdr (assoc 10 s)))
  784.             (setq radius1 (* (cdr (assoc 40 s)) s_factor))
  785.  
  786.             (setq clip1_normal 
  787.  
  788.                 (trans
  789.  
  790.                 (list
  791.                 (- (sin (cdr (assoc 50 s))))
  792.                 (cos (cdr (assoc 50 s)))
  793.                 0.0
  794.                 )
  795.  
  796.                 (cdr (assoc 210 s))
  797.                 
  798.                 0
  799.  
  800.                 T
  801.  
  802.                 )
  803.  
  804.             )
  805.             
  806.             (if    trans_matrix
  807.  
  808.                 (setq clip1_normal
  809.  
  810.                     (mapcar '-
  811.  
  812.                     (MCS_to_WCS clip1_normal trans_matrix)
  813.                     (MCS_to_WCS (list 0 0 0) trans_matrix)
  814.                 
  815.                     )
  816.  
  817.                 )
  818.             )
  819.  
  820.             (setq clip2_normal 
  821.  
  822.                 (trans
  823.  
  824.                 (list
  825.                 (sin (cdr (assoc 51 s)))
  826.                 (- (cos (cdr (assoc 51 s))))
  827.                 0.0
  828.                 )
  829.  
  830.                 (cdr (assoc 210 s))
  831.                 
  832.                 0
  833.  
  834.                 T
  835.  
  836.                 )
  837.  
  838.             )
  839.             
  840.             (if    trans_matrix
  841.  
  842.                 (setq clip2_normal
  843.  
  844.                     (mapcar '-
  845.  
  846.                     (MCS_to_WCS clip2_normal trans_matrix)
  847.                     (MCS_to_WCS (list 0 0 0) trans_matrix)
  848.                 
  849.                     )
  850.  
  851.                 )
  852.             )
  853.  
  854.  
  855.  
  856.  
  857.  
  858.             (setq    arc_center2
  859.  
  860.                 (trans
  861.  
  862.                 (mapcar '+
  863.                 arc_center
  864.                 (list 0 0 (cdr (assoc 39 s)))
  865.                 )
  866.  
  867.                 (cdr (assoc 210 s))
  868.  
  869.                 0
  870.  
  871.                 )
  872.             )
  873.                 
  874.  
  875.             (setq     arc_center
  876.  
  877.                 (trans arc_center (cdr (assoc 210 s)) 0)
  878.  
  879.             )
  880.  
  881.  
  882.             (if    trans_matrix
  883.  
  884.                 (setq    arc_center
  885.                     (MCS_to_WCS arc_center trans_matrix)
  886.                     arc_center2
  887.                     (MCS_to_WCS arc_center2 trans_matrix)
  888.                 )
  889.             )
  890.  
  891.             (setq big_angle? nil)
  892.  
  893.             ;* if arc is greater than 180 degrees need to draw
  894.             ;* two VIVID cones w/ clipping planes
  895.  
  896.             (if    (>     (cdr (assoc 50 s))
  897.                     (cdr (assoc 51 s))
  898.                 )
  899.  
  900.                 (if    (>    (- (+ (* 2 pi) (cdr (assoc 51 s)))
  901.                            (cdr (assoc 50 s))
  902.                         )
  903.  
  904.                         pi
  905.  
  906.                     )
  907.  
  908.                     (setq big_angle? T)
  909.  
  910.                 ) ; close if
  911.  
  912.                 (if    (>    (- (cdr (assoc 51 s))
  913.                            (cdr (assoc 50 s))
  914.                         )
  915.  
  916.                         pi
  917.  
  918.                     )
  919.  
  920.                     (setq big_angle? T)
  921.  
  922.                 ) ; close if
  923.  
  924.             ); close if
  925.  
  926.  
  927.             (if    big_angle?
  928.  
  929.                 (progn
  930.  
  931.                 (setq theta (+ (cdr (assoc 50 s))  pi ))
  932.  
  933.                 (setq clip3_normal 
  934.     
  935.                     (trans
  936.     
  937.                     (list
  938.                     (- (sin theta))
  939.                     (cos theta)
  940.                     0.0
  941.                     )
  942.     
  943.                     (cdr (assoc 210 s))
  944.                     
  945.                     0
  946.     
  947.                     T
  948.  
  949.                     )
  950.     
  951.                 )
  952.                 
  953.                 (if    trans_matrix
  954.     
  955.                     (setq clip3_normal
  956.     
  957.                         (mapcar '-
  958.     
  959.                         (MCS_to_WCS clip3_normal trans_matrix)
  960.                         (MCS_to_WCS (list 0 0 0) trans_matrix)
  961.                     
  962.                         )
  963.     
  964.                     )
  965.                 )
  966.  
  967.  
  968.  
  969.                 (setq new
  970.                     
  971.                     (cons
  972.  
  973.                     (car old)
  974.  
  975.                     (list
  976.                     (append
  977.  
  978.                     (cadr old)
  979.  
  980.                     (list
  981.  
  982.                     " "
  983.  
  984.                     (strcat
  985.                     "cone { base "
  986.                     (real_to_string arc_center)
  987.                     )
  988.  
  989.                     (strcat
  990.                     "apex "
  991.                     (real_to_string arc_center2)
  992.                     )
  993.  
  994.                     (strcat "base_radius "
  995.                     (rtos radius1 2 6)
  996.                     )
  997.                     
  998.                     (strcat "apex_radius "
  999.                     (rtos radius1 2 6)
  1000.                     )
  1001.  
  1002.                     (strcat "clip { center "
  1003.                     (real_to_string arc_center)
  1004.                     " normal "
  1005.                     (real_to_string clip1_normal)
  1006.                     "}"
  1007.  
  1008.                     "}"
  1009.  
  1010.                     )
  1011.  
  1012.                     ;* another cone
  1013.  
  1014.                     " "
  1015.                     
  1016.                     (strcat
  1017.                     "cone { base "
  1018.                     (real_to_string arc_center)
  1019.                     )
  1020.  
  1021.                     (strcat
  1022.                     "apex "
  1023.                     (real_to_string arc_center2)
  1024.                     )
  1025.  
  1026.                     (strcat "base_radius "
  1027.                     (rtos radius1 2 6)
  1028.                     )
  1029.                     
  1030.                     (strcat "apex_radius "
  1031.                     (rtos radius1 2 6)
  1032.                     )
  1033.  
  1034.                     (strcat "clip { center "
  1035.                     (real_to_string arc_center)
  1036.                     " normal "
  1037.                     (real_to_string clip2_normal)
  1038.                     "}"
  1039.                     )
  1040.  
  1041.  
  1042.                     (strcat "clip { center "
  1043.                     (real_to_string arc_center)
  1044.                     " normal "
  1045.                     (real_to_string clip3_normal)
  1046.                     "}"
  1047.                     "}"
  1048.                     )
  1049.  
  1050.                     ) ; close list
  1051.                     ) ; close append
  1052.                     ) ; close list
  1053.                     ) ; close cons
  1054.  
  1055.                 ); close setq
  1056.  
  1057.                 (setq master (subst new old master))
  1058.                 (setq old new)
  1059.                 
  1060.                 (setq arc_c_count (+ arc_c_count 2))
  1061.  
  1062.     
  1063.                 ) ; close progn
  1064.     
  1065.     
  1066.                 (progn
  1067.  
  1068.                 (setq new
  1069.                     
  1070.                     (cons
  1071.  
  1072.                     (car old)
  1073.  
  1074.                     (list
  1075.                     (append
  1076.  
  1077.                     (cadr old)
  1078.  
  1079.                     (list
  1080.  
  1081.                     " "
  1082.                                                    
  1083.                     (strcat
  1084.                     "cone { base "
  1085.                     (real_to_string arc_center)
  1086.                     )
  1087.  
  1088.                     (strcat
  1089.                     "apex "
  1090.                     (real_to_string arc_center2)
  1091.                     )
  1092.  
  1093.                     (strcat "base_radius "
  1094.                     (rtos radius1 2 6)
  1095.                     )
  1096.                     
  1097.                     (strcat "apex_radius "
  1098.                     (rtos radius1 2 6)
  1099.                     )
  1100.  
  1101.                     (strcat "clip { center "
  1102.                     (real_to_string arc_center)
  1103.                     " normal "
  1104.                     (real_to_string clip1_normal)
  1105.                     "}"
  1106.                     )
  1107.  
  1108.  
  1109.                     (strcat "clip { center "
  1110.                     (real_to_string arc_center)
  1111.                     " normal "
  1112.                     (real_to_string clip2_normal)
  1113.                     "}"
  1114.                     "}"
  1115.                     )
  1116.  
  1117.                     ) ; close list
  1118.                     ) ; close append
  1119.                     ) ; close list
  1120.                     ) ; close cons
  1121.  
  1122.                 ); close setq
  1123.  
  1124.                 (setq master (subst new old master))
  1125.                 (setq old new)
  1126.  
  1127.                 (setq arc_c_count (1+ arc_c_count))
  1128.  
  1129.                 )  ;close progn
  1130.  
  1131.             ) ; close if
  1132.             
  1133.             ) ; close cond clause
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1142. ;;    3d polygon mesh-- not polyface mesh.
  1143. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1144.  
  1145.             (
  1146.             (and     (= (cdr (assoc 0 s)) "POLYLINE")
  1147.                 (= (boole 1 16 (cdr (assoc 70 s))) 16)
  1148.                 (= (boole 1 64 (cdr (assoc 70 s))) 0)
  1149.                 (check_layer block_layer)
  1150.             )
  1151.  
  1152.             (progn
  1153.  
  1154.             ;* increment either smoothed or faceted counter
  1155.             (setq mesh_smooth (smooth_entity))
  1156.  
  1157.             (if    (smoothed)
  1158.                 (setq 3dmesh_count (1+ 3dmesh_count)
  1159.                 normal_index 0
  1160.                 )    
  1161.                 (setq f_3dmesh_count (1+ f_3dmesh_count))
  1162.             )
  1163.  
  1164.             (print_count)
  1165.             
  1166.             (draw_mesh trans_matrix)
  1167.  
  1168.             
  1169.             )
  1170.  
  1171.             )
  1172.  
  1173. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1174. ;;  polyface mesh.
  1175. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1176.  
  1177.             (
  1178.             (and     (= (cdr (assoc 0 s)) "POLYLINE") 
  1179.                 (check_layer block_layer)
  1180.                 
  1181.                 (= 64  (boole 1 64 (cdr (assoc 70 s))))  
  1182.             )
  1183.  
  1184.             
  1185.  
  1186.             ;* increment either smoothed or faceted counter
  1187.             (setq mesh_smooth (smooth_entity))
  1188.  
  1189.             (if    (smoothed)
  1190.                 (setq pface_count (1+ pface_count)
  1191.                 normal_index 0
  1192.                 )    
  1193.                 (setq f_pface_count (1+ f_pface_count))
  1194.             )
  1195.  
  1196.  
  1197.  
  1198.  
  1199.             (print_count)
  1200.             (setq vertex_list (list nil))
  1201.  
  1202.             (setq patch_list nil)
  1203.             (setq normal_list nil)
  1204.  
  1205.             (setq s (entget (setq e (entnext e)) (list "VIVID_RJH")))
  1206.  
  1207.             (while    (/= (cdr (assoc 0 s)) "SEQEND")
  1208.                 
  1209.                 (cond
  1210.                     (
  1211.                     (= (boole 1 (cdr (assoc 70 s)) (+ 128 64)) 192)
  1212.  
  1213.                     ;; this is a vertex -- add to list
  1214.  
  1215.                     (setq vertex_list (append vertex_list (list (cdr (assoc 10 s)))))
  1216.                     )
  1217.  
  1218.                     (
  1219.                     (= (boole 1 (cdr (assoc 70 s)) 128) 128)
  1220.  
  1221.                     ;; this is a face vertex-- first determine
  1222.                     ;; if it has less than three sides-- skip it if
  1223.                     ;; it does.  Then decide whether to draw a three
  1224.                     ;; or four sided polygon.  Use the previously
  1225.                     ;; assembled vertices in vertex_list.
  1226.  
  1227.                     (if    (/= 0 (cdr (assoc 73 s)))
  1228.                         (progn
  1229.                                                 (if (= 0 (cdr (assoc 74 s)))
  1230.  
  1231.  
  1232.                             ;; triangular face here
  1233.  
  1234.                             (if    (smoothed)
  1235.  
  1236.                             ; smooth
  1237.                             (progn
  1238.  
  1239.                                 (setq pface_p_count (1+ pface_p_count))
  1240.   
  1241.                                 (add_patch    
  1242.                                 (nth (abs (cdr (assoc 71 s))) vertex_list)
  1243.                                 (nth (abs (cdr (assoc 72 s))) vertex_list)
  1244.                                 (nth (abs (cdr (assoc 73 s))) vertex_list)                    
  1245.                                 trans_matrix
  1246.                                 )
  1247.                             ) ; close progn
  1248.  
  1249.                             ;faceted
  1250.                             (progn
  1251.  
  1252.                                 (setq f_pface_p_count (1+ f_pface_p_count))
  1253.   
  1254.                                 (draw_3    
  1255.                                 (nth (abs (cdr (assoc 71 s))) vertex_list)
  1256.                                 (nth (abs (cdr (assoc 72 s))) vertex_list)
  1257.                                 (nth (abs (cdr (assoc 73 s))) vertex_list)                    
  1258.                                 trans_matrix
  1259.                                 )
  1260.                             ) ; close progn
  1261.                             ) ; close if
  1262.  
  1263.                             ;; four sided here-- need to check
  1264.                             ;; for coplanar vertices in faceted case
  1265.  
  1266.                             (if    (smoothed)    
  1267.  
  1268.                             ; smooth 
  1269.                                 (progn
  1270.                                     (add_patch
  1271.                                     (nth (abs (cdr (assoc 71 s))) vertex_list)
  1272.                                     (nth (abs (cdr (assoc 72 s))) vertex_list)                    
  1273.                                     (nth (abs (cdr (assoc 73 s))) vertex_list)                    
  1274.                                     trans_matrix
  1275.                                        )
  1276.  
  1277.                                     (add_patch
  1278.                                     (nth (abs (cdr (assoc 71 s))) vertex_list)                            
  1279.                                     (nth (abs (cdr (assoc 73 s))) vertex_list)                    
  1280.                                     (nth (abs (cdr (assoc 74 s))) vertex_list)
  1281.                                 trans_matrix
  1282.                                 )
  1283.  
  1284.                                 (setq pface_p_count (+ pface_p_count 2))
  1285.  
  1286.                         
  1287.                             ) ; close progn
  1288.  
  1289.                             ;faceted
  1290.                             (if    (inters
  1291.                                   (nth (abs (cdr (assoc 71 s))) vertex_list)
  1292.                                 (nth (abs (cdr (assoc 73 s))) vertex_list)
  1293.                                 (nth (abs (cdr (assoc 72 s))) vertex_list)
  1294.                                 (nth (abs (cdr (assoc 74 s))) vertex_list)
  1295.                                 T
  1296.                                 )
  1297.                                 
  1298.                                 ;co-planar
  1299.                                 (progn
  1300.                                 (draw_4
  1301.                                     (nth (abs (cdr (assoc 71 s))) vertex_list)                            
  1302.                                 (nth (abs (cdr (assoc 72 s))) vertex_list)
  1303.                                     (nth (abs (cdr (assoc 73 s))) vertex_list)                    
  1304.                                     (nth (abs (cdr (assoc 74 s))) vertex_list)
  1305.                                 trans_matrix
  1306.                                     )
  1307.                                 (setq f_pface_p_count (1+ f_pface_p_count))
  1308.                                 ) ; close progn
  1309.                                 
  1310.                                 ;non-coplanar
  1311.                                 (progn
  1312.                                         (draw_3
  1313.                                     (nth (abs (cdr (assoc 71 s))) vertex_list)
  1314.                                     (nth (abs (cdr (assoc 72 s))) vertex_list)                    
  1315.                                     (nth (abs (cdr (assoc 73 s))) vertex_list)                    
  1316.                                     trans_matrix
  1317.                                            )
  1318.  
  1319.                                         (draw_3
  1320.                                     (nth (abs (cdr (assoc 71 s))) vertex_list)                            
  1321.                                     (nth (abs (cdr (assoc 73 s))) vertex_list)                    
  1322.                                     (nth (abs (cdr (assoc 74 s))) vertex_list)
  1323.                                 trans_matrix
  1324.                                     )                    
  1325.  
  1326.                                     (setq f_pface_p_count (+ f_pface_p_count 2))
  1327.  
  1328.                         
  1329.                                 ) ; close progn
  1330.  
  1331.                             ) ; close if
  1332.                             ); close if
  1333.                         
  1334.                         ); close progn
  1335.                         ); close if
  1336.                     )
  1337.                     ) ;close cond clause
  1338.                 )  ;close cond
  1339.  
  1340.                 (setq s (entget (setq e (entnext e)) (list "VIVID_RJH")))
  1341.  
  1342.             ) ;close while
  1343.             
  1344.             (if    (smoothed)
  1345.                 (progn
  1346.         
  1347.                        ;(avg_normals)
  1348.                     (draw_patch)
  1349.                 )
  1350.             )
  1351.  
  1352.     
  1353.              
  1354.  
  1355.             ) ;close cond clause
  1356.                 
  1357.  
  1358.  
  1359. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1360. ;; lights 
  1361. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1362.  
  1363.             (
  1364.             (and     (= (cdr (assoc 0 s)) "INSERT") 
  1365.                 (OR
  1366.                     (= (cdr (assoc 2 s)) "L_POINT")
  1367.                     (= (cdr (assoc 2 s)) "L_DIRECT")                
  1368.                     (= (cdr (assoc 2 s)) "L_SPHERE")
  1369.                     (= (cdr (assoc 2 s)) "L_SPOT")
  1370.                     
  1371.                 )
  1372.  
  1373.                 (check_layer block_layer)  ;layer thawed and on
  1374.                 (= (cdr (assoc 66 s)) 1)  ;attributes must follow    
  1375.             )
  1376.             (progn
  1377.  
  1378.                 (setq light_count (1+ light_count))
  1379.                 (print_count)
  1380.  
  1381.                 (setq v_lights (cons "light={" v_lights))
  1382.  
  1383.                 (cond    (
  1384.                     (= (cdr (assoc 2 s)) "L_POINT")
  1385.                     (setq v_lights (cons "type point;" v_lights))
  1386.                     )
  1387.  
  1388.                     (
  1389.                     (= (cdr (assoc 2 s)) "L_SPHERE")
  1390.                     (setq v_lights (cons "type spherical;" v_lights))
  1391.                     ;; calculate radius based on scale
  1392.                     (setq v_lights     (cons 
  1393.                             (strcat
  1394.                             "radius "
  1395.  
  1396.                             (rtos
  1397.                             (abs (* (cdr (assoc 41 s)) s_factor))
  1398.                             2 6 ) ;close rtos
  1399.                             
  1400.                             ) ;close strcat
  1401.                             v_lights
  1402.                             ) ;close cons
  1403.                     )  ;close setq
  1404.                     )
  1405.  
  1406.                     (
  1407.                     (= (cdr (assoc 2 s)) "L_DIRECT")
  1408.                     (setq v_lights (cons "type directional;" v_lights))
  1409.                     )
  1410.  
  1411.                     (
  1412.                     (= (cdr (assoc 2 s)) "L_SPOT")
  1413.                     (setq v_lights (cons "type spot;" v_lights))
  1414.                     )
  1415.                                         
  1416.                 )
  1417.  
  1418.  
  1419.  
  1420.                 ;;calculate position for point, sphericals, spot
  1421.  
  1422.                 (if    (/= (cdr (assoc 2 s)) "L_DIRECT")
  1423.                     (progn
  1424.  
  1425.                         (if    (= b_flag 0)
  1426.                             (setq temp1 (trans (cdr (assoc 10 s)) e 0))  ;translate to WCS
  1427.                             (setq temp1 (mcs_to_wcs (trans (cdr (assoc 10 s)) (cdr (assoc 210 s)) 0) trans_matrix))
  1428.                         )
  1429.  
  1430.                         (setq v_lights
  1431.                          (cons
  1432.                           (strcat
  1433.                             "position "
  1434.                             (rtos (car temp1) 2 6)
  1435.                             " "
  1436.                             (rtos (cadr temp1) 2 6)
  1437.                             " "
  1438.                             (rtos (caddr temp1) 2 6)
  1439.                                " "
  1440.                           )
  1441.                           v_lights
  1442.                          )
  1443.                         )
  1444.  
  1445.  
  1446.  
  1447.                     ) ;close progn
  1448.  
  1449.                                                     
  1450.                 ) ;close if
  1451.  
  1452.                 (setq e (entnext e)) 
  1453.                 (setq s (entget e (list "VIVID_RJH")))
  1454.                 (while                
  1455.                     (= (cdr (assoc 0 s)) "ATTRIB")
  1456.                     (if    (or (= (cdr (assoc 2 s)) "NO_SHADOWS")
  1457.                              (= (cdr (assoc 2 s)) "NO_SPEC")                        
  1458.                          )
  1459.  
  1460.                          (if     (or (= (cdr (assoc 1 s)) "Y") 
  1461.                              (= (cdr (assoc 1 s)) "YES" )
  1462.                              (= (cdr (assoc 1 s)) "y" )
  1463.                              (= (cdr (assoc 1 s)) "yes" )
  1464.                                  )
  1465.                                                       
  1466.                             (setq v_lights    (cons
  1467.                                     (strcat
  1468.                                         (strcase (cdr (assoc 2 s)) T)
  1469.                                         " "
  1470.                                           
  1471.                                     )
  1472.                                     v_lights
  1473.                                     )
  1474.                             )
  1475.  
  1476.                         ) ; close if
  1477.                     
  1478.                               
  1479.                         (setq v_lights    (cons
  1480.                                 (strcat
  1481.                                     (strcase (cdr (assoc 2 s)) T)
  1482.                                     " "
  1483.                                     (strcase (cdr (assoc 1 s)) T)
  1484.                                     " "
  1485.                                 )
  1486.                                 v_lights
  1487.                                 )
  1488.                         )
  1489.  
  1490.                     ) ; close if
  1491.  
  1492.                     (setq e (entnext e))
  1493.                     (setq s (entget e (list "VIVID_RJH")))
  1494.                 )
  1495.                 (setq v_lights (cons "}" v_lights))
  1496.                             
  1497.             )                            
  1498.                           
  1499.  
  1500.             )
  1501.  
  1502. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1503. ;;   extruded circles-- convert to vivid cones (true cylinders)
  1504. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1505.  
  1506.         
  1507.             (
  1508.  
  1509.             (and     (= (cdr (assoc 0 s)) "CIRCLE") 
  1510.                 (check_layer block_layer)
  1511.                 (and
  1512.                     (assoc 39 s)
  1513.                     (/= (cdr (assoc 39 s)) 0)
  1514.                 )
  1515.                 
  1516.             )
  1517.  
  1518.             (progn
  1519.  
  1520.                 (print_count)
  1521.                 (setq circle_count (1+ circle_count))
  1522.                 
  1523.                 ;  multiply thickness by extrusion vector
  1524.                 ;  and add to coordinates to obtain 2nd center point
  1525.                 ;  first translate to WCS from ECS if not a block.
  1526.  
  1527.  
  1528.                 (if    (= b_flag 0)
  1529.                     (setq a (trans (cdr (assoc 10 s)) e 0))
  1530.                     (setq a (trans (cdr (assoc 10 s)) (cdr (assoc 210 s)) 0))
  1531.                 )
  1532.  
  1533.                    (setq ee (cdr (assoc 210 s)))
  1534.                    (setq ee  (mapcar '(lambda (x)
  1535.                          (* x (cdr (assoc 39 s)))
  1536.                          )
  1537.                           ee
  1538.                       )
  1539.                 )
  1540.                 (setq b (mapcar '+ a ee))
  1541.  
  1542.  
  1543.                 (setq c (rtos (* (cdr (assoc 40 s)) s_factor) 2 6 ))  ;get radius
  1544.  
  1545.                 ;; translate from MCS to WCS if this is a block
  1546.  
  1547.                 (if    (> b_flag 0)
  1548.                     (progn
  1549.                         (setq a (MCS_to_WCS
  1550.                             a 
  1551.                             trans_matrix))
  1552.                         (setq b (MCS_to_WCS 
  1553.                              b 
  1554.                             trans_matrix))
  1555.                         
  1556.                     )
  1557.                 )
  1558.  
  1559.                                 
  1560.                 (setq new
  1561.                     (cons
  1562.                         (car old)
  1563.                         (list
  1564.                          (cons             
  1565.                         (strcat 
  1566.                         "cone {base "
  1567.                         (rtos (car  a) 2 6)
  1568.                         " "
  1569.                         (rtos (cadr a) 2 6)
  1570.                         " "
  1571.                         (rtos (caddr a) 2 6)
  1572.                         "  base_radius "
  1573.                         c
  1574.                         "  apex "
  1575.                         (rtos (car b) 2 6)
  1576.                         " "
  1577.                         (rtos (cadr b) 2 6)
  1578.                         " "
  1579.                         (rtos (caddr b) 2 6)
  1580.                         "  apex_radius "
  1581.                         c
  1582.                         "}"
  1583.                         
  1584.                         )
  1585.                         (cadr old)
  1586.                         ))
  1587.                     )
  1588.                 )
  1589.                 (setq master (subst new old master))
  1590.                 
  1591.                 
  1592.                 
  1593.             ) ; close progn
  1594.             )            
  1595. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1596. ;;
  1597. ;;   V_CONE??-- convert to vivid cone w/ height = base_radius * ??
  1598. ;;                    apex_radius = 0
  1599. ;;    searches for a block whose name starts w/ "V_CONE" and ends with
  1600. ;;    a valid number.  The number is the cone height to radius ratio.
  1601. ;;    e.g. a V_CONE6 block converts to a cone whose height is 6 times
  1602. ;;    its radius (these are pointy cones-- apex_radius always = 0)
  1603. ;;
  1604. ;;
  1605. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1606.  
  1607.         
  1608.             (
  1609.  
  1610.             (and     (= (cdr (assoc 0 s)) "INSERT") 
  1611.                 (= (substr (cdr (assoc 2 s)) 1 6) "V_CONE")
  1612.                 (/= (setq cone_ratio (atof (substr (cdr (assoc 2 s)) 7))) 0.0)
  1613.                 (check_layer block_layer)  ;layer thawed and on                
  1614.         
  1615.             )
  1616.  
  1617.  
  1618.             (progn
  1619.  
  1620.                 (print_count)
  1621.                 (setq circle_count (1+ circle_count))
  1622.                 
  1623.                 ;  multiply thickness by extrusion vector
  1624.                 ;  and add to coordinates to obtain 2nd center point
  1625.                 ;  first translate to WCS from ECS if not a block.
  1626.  
  1627.  
  1628.                 (if    (= b_flag 0)
  1629.                     (setq a (trans (cdr (assoc 10 s)) e 0))
  1630.                     (setq a (trans (cdr (assoc 10 s)) (cdr (assoc 210 s)) 0))
  1631.                 )
  1632.  
  1633.                    (setq ee (cdr (assoc 210 s)))
  1634.                    (setq ee  (mapcar '(lambda (x)
  1635.                          (* x (abs (cdr (assoc 41 s))) cone_ratio)
  1636.                          )
  1637.                           ee
  1638.                       )
  1639.                 )
  1640.                 (setq b (mapcar '+ a ee))
  1641.  
  1642.  
  1643.                 (setq c (rtos (* (abs (cdr (assoc 41 s))) s_factor) 2 6 ))  ;get radius
  1644.  
  1645.                 ;; translate from MCS to WCS if this is a block
  1646.  
  1647.                 (if    (> b_flag 0)
  1648.                     (progn
  1649.                         (setq a (MCS_to_WCS
  1650.                             a 
  1651.                             trans_matrix))
  1652.                         (setq b (MCS_to_WCS 
  1653.                              b 
  1654.                             trans_matrix))
  1655.                         
  1656.                     )
  1657.                 )
  1658.  
  1659.                                 
  1660.                 (setq new
  1661.                     (cons
  1662.                         (car old)
  1663.                         (list
  1664.                          (cons             
  1665.                         (strcat 
  1666.                         "cone {base "
  1667.                         (rtos (car  a) 2 6)
  1668.                         " "
  1669.                         (rtos (cadr a) 2 6)
  1670.                         " "
  1671.                         (rtos (caddr a) 2 6)
  1672.                         "  base_radius "
  1673.                         c
  1674.                         "  apex "
  1675.                         (rtos (car b) 2 6)
  1676.                         " "
  1677.                         (rtos (cadr b) 2 6)
  1678.                         " "
  1679.                         (rtos (caddr b) 2 6)
  1680.                         "  apex_radius  0 "
  1681.                         "}"
  1682.                         
  1683.                         )
  1684.                         (cadr old)
  1685.                         ))
  1686.                     )
  1687.                 )
  1688.                 (setq master (subst new old master))
  1689.                 
  1690.                 
  1691.                 
  1692.             ) ; close progn
  1693.             )            
  1694.  
  1695.  
  1696.  
  1697. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1698. ;;   spheres -- identified by block v_sphere-- unit sphere-- uses x scale
  1699. ;;        factor for radius.
  1700. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1701.  
  1702.         
  1703.             (
  1704.  
  1705.             (and     (= (cdr (assoc 0 s)) "INSERT") 
  1706.                 (= (cdr (assoc 2 s)) "V_SPHERE")
  1707.                 (check_layer block_layer)  ;layer thawed and on                
  1708.         
  1709.             )
  1710.  
  1711.             (progn
  1712.                 
  1713.  
  1714.                 (print_count)
  1715.                 (setq sphere_count (1+ sphere_count))
  1716.                                 
  1717.                 ;  first translate to WCS from ECS or MCS (if a block)
  1718.  
  1719.                 
  1720.                 (if    (= b_flag 0)
  1721.                     (setq a (trans (cdr (assoc 10 s)) e 0))
  1722.                     (setq a (MCS_to_WCS (trans (cdr (assoc 10 s)) (cdr (assoc 210 s)) 0) trans_matrix))
  1723.                 )
  1724.                                                 
  1725.                 (setq new
  1726.                     (cons
  1727.                         (car old)
  1728.                         (list
  1729.                          (cons             
  1730.                         (strcat 
  1731.                         "sphere {center "
  1732.                         (rtos (car  a) 2 6)
  1733.                         " "
  1734.                         (rtos (cadr a) 2 6)
  1735.                         " "
  1736.                         (rtos (caddr a) 2 6)
  1737.                         " radius "
  1738.                         (rtos (* (abs (cdr (assoc 41 s))) s_factor) 2 6)
  1739.                         "}"                                                
  1740.                         )
  1741.  
  1742.                         (cadr old)
  1743.                         ))
  1744.                     )
  1745.                 )
  1746.                 (setq master (subst new old master))
  1747.                 
  1748.                 
  1749.             ) ; close progn
  1750.             )            
  1751.  
  1752. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1753. ;;   disks -- identified by block v_disk-- unit disk-- uses x scale
  1754. ;;        factor for radius.
  1755. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1756.  
  1757.         
  1758.             (
  1759.  
  1760.             (and     (= (cdr (assoc 0 s)) "INSERT") 
  1761.                 (= (cdr (assoc 2 s)) "V_DISK")
  1762.                 (check_layer block_layer)  ;layer thawed and on                
  1763.         
  1764.             )
  1765.  
  1766.             (progn
  1767.                 
  1768.  
  1769.                 (print_count)
  1770.                 (setq disk_count (1+ disk_count))
  1771.                                 
  1772.                 ;  first translate to WCS from ECS or MCS (if a block)
  1773.  
  1774.                 
  1775.                 (if    (= b_flag 0)
  1776.                                         (progn
  1777.                                         (setq a (trans (cdr (assoc 10 s)) e 0))
  1778.                                         (setq b (cdr (assoc 210 s)))
  1779.                                         )
  1780.  
  1781.                     (progn
  1782.                     (setq a (MCS_to_WCS (trans (cdr (assoc 10 s)) (cdr (assoc 210 s)) 0) trans_matrix))
  1783.                                         (setq b 
  1784.                     (mapcar '-
  1785.  
  1786.                         (MCS_to_WCS (cdr (assoc 210 s)) trans_matrix)
  1787.                         (MCS_to_WCS '(0 0 0) trans_matrix)
  1788.                                         )
  1789.                     )
  1790.                     )
  1791.                 )
  1792.                                                 
  1793.                 (setq new
  1794.                     (cons
  1795.                         (car old)
  1796.                         (list
  1797.                          (cons             
  1798.                         (strcat 
  1799.                         "ring={center="
  1800.                         (rtos (car  a) 2 6)
  1801.                         " "
  1802.                         (rtos (cadr a) 2 6)
  1803.                         " "
  1804.                         (rtos (caddr a) 2 6)
  1805.                         " radius "
  1806.                         (rtos (* (cdr (assoc 41 s)) s_factor) 2 6)
  1807.                         " normal "
  1808.                         (rtos (car  b) 2 6)
  1809.                         " "
  1810.                         (rtos (cadr b) 2 6)
  1811.                         " "
  1812.                         (rtos (caddr b) 2 6)
  1813.                         
  1814.                         " }"                                                
  1815.                         )
  1816.  
  1817.                         (cadr old)
  1818.                         ))
  1819.                     )
  1820.                 )
  1821.                 (setq master (subst new old master))
  1822.                 
  1823.                 
  1824.             ) ; close progn
  1825.             )            
  1826.  
  1827.  
  1828.  
  1829. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1830. ;;   half disks -- identified by block v_disk2-- unit disk w/ clipping
  1831. ;;        plane
  1832. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1833.  
  1834.         
  1835.             (
  1836.  
  1837.             (and     (= (cdr (assoc 0 s)) "INSERT") 
  1838.                 (= (cdr (assoc 2 s)) "V_DISK2")
  1839.                 (check_layer block_layer)  ;layer thawed and on                
  1840.         
  1841.             )
  1842.  
  1843.             (progn
  1844.                 
  1845.  
  1846.                 (print_count)
  1847.                 (setq disk_count (1+ disk_count))
  1848.                                 
  1849.                 ;  first translate to WCS from ECS or MCS (if a block)
  1850.  
  1851.                 
  1852.                 (if    (= b_flag 0)
  1853.                                         (progn
  1854.                                         (setq a (trans (cdr (assoc 10 s)) e 0))
  1855.                                         (setq b (cdr (assoc 210 s)))
  1856.                                         )
  1857.  
  1858.                     (progn
  1859.                     (setq a (MCS_to_WCS (trans (cdr (assoc 10 s)) (cdr (assoc 210 s)) 0) trans_matrix))
  1860.  
  1861.                                         (setq b 
  1862.                     (mapcar '-
  1863.  
  1864.                         (MCS_to_WCS (cdr (assoc 210 s)) trans_matrix)
  1865.                         (MCS_to_WCS '(0 0 0) trans_matrix)
  1866.                                         )
  1867.                     ); close setq
  1868.  
  1869.  
  1870.                     ) ; close progn
  1871.  
  1872.                 ); close if
  1873.  
  1874.                     
  1875.                 ;; rotate clipping normal about ECS origin if nec.
  1876.  
  1877.                 (if    (/= 0 (setq theta (cdr (assoc 50 s))))
  1878.  
  1879.                     (setq clip_normal 
  1880.                     (list
  1881.                     (cos theta)
  1882.                     (sin theta)
  1883.                     0
  1884.                     )
  1885.                     )
  1886.  
  1887.                     (setq clip_normal (list 1 0 0))
  1888.  
  1889.                 ) ; close if
  1890.  
  1891.  
  1892.                 (setq clip_normal (trans clip_normal (cdr (assoc 210 s)) 0 T))
  1893.  
  1894.                 (if     trans_matrix
  1895.  
  1896.                                     (setq clip_normal 
  1897.                     (mapcar '-
  1898.                         (MCS_to_WCS clip_normal trans_matrix)
  1899.                         (MCS_to_WCS '(0 0 0) trans_matrix)
  1900.                                     )
  1901.                     ); close setq
  1902.  
  1903.                 ); close if
  1904.  
  1905.  
  1906.                                                 
  1907.                 (setq new
  1908.                     (cons
  1909.                         (car old)
  1910.                         (list
  1911.                          (cons             
  1912.                         (strcat 
  1913.                         "ring {center "
  1914.                         (rtos (car  a) 2 6)
  1915.                         " "
  1916.                         (rtos (cadr a) 2 6)
  1917.                         " "
  1918.                         (rtos (caddr a) 2 6)
  1919.                         " radius "
  1920.                         (rtos (* (cdr (assoc 41 s)) s_factor) 2 6)
  1921.                         " normal "
  1922.                         (rtos (car  b) 2 6)
  1923.                         " "
  1924.                         (rtos (cadr b) 2 6)
  1925.                         " "
  1926.                         (rtos (caddr b) 2 6)
  1927.                         " "                                                
  1928.                         ) ;end strcat
  1929.  
  1930.                             (cons
  1931.                             (strcat
  1932.                             "clip {center "
  1933.                             (real_to_string a)
  1934.                             " normal "
  1935.                             (real_to_string clip_normal)
  1936.                             " }}"
  1937.                             ) ; close strcat
  1938.                             (cadr old)
  1939.                             );close cons
  1940.  
  1941.                         ) ;close cons
  1942.                         ) ;close list
  1943.                     )
  1944.                 )
  1945.                 (setq master (subst new old master))
  1946.                 
  1947.                 
  1948.             ) ; close progn
  1949.             )            
  1950.  
  1951.  
  1952.  
  1953.         
  1954.         
  1955.  
  1956.  
  1957. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1958. ;;
  1959. ;;  "INSERT" (Block Insertion).  Check to make sure that this
  1960. ;;  is a general purpose block-- e.g. that it is not one of the special
  1961. ;;  blocks whose names begin with "V_".  
  1962. ;;
  1963. ;;  General purpose blocks generate a recursive call to v_main so that the
  1964. ;;  entities within the block can be processed similarly to the main entities.
  1965. ;;  b_flag, a nesting indicator, is incremented before calling v_main.
  1966. ;;  V-main is also called with a transformation matrix to translate coordinates
  1967. ;;  from the block's coordinate system (MCS) to the WCS.  This transformation
  1968. ;;  is based on the rotation angle, scale, and extrusion vector of the particular
  1969. ;;  INSERT.  If this is a nested block, it will also be dependent on the 
  1970. ;;  parent block's transformation matrix.  If b_flag is non-zero, meaning we
  1971. ;;  are now processing a block-- the routines for processing each type of
  1972. ;;  entity in v_main will translate the coordinates by using the transformation
  1973. ;;  matrix.  The matrix is a 4 x 4 matrix which is equivalent to AutoLISP's
  1974. ;;  matrix provided by (nentsel)-- (this is actually a 3 x 4 matrix-- an
  1975. ;;  additional row of 0 0 0 1 is provided to make matrix manipulation easier.
  1976. ;;
  1977. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1978.  
  1979.  
  1980.         (
  1981.         (and    (= (cdr (assoc 0 s)) "INSERT")
  1982.             (/= (substr (cdr (assoc 2 s)) 1 2) "V_")
  1983.             (check_layer block_layer)
  1984.         )
  1985.  
  1986.         
  1987.  
  1988.         (progn
  1989.         
  1990.         
  1991. ;; first determine if this INSERT has an extrusion vector other than 0 0 1.
  1992. ;; if it does, transform according to the Arbitrary Axis Algorith documented
  1993. ;; in Appendix C of the AutoCAD manual.
  1994.  
  1995.         (if    (equal (cdr (assoc 210 s)) '( 0 0 1))
  1996.             
  1997.             (setq temp_matrix    (list
  1998.                         (list 1 0 0 0)
  1999.                         (list 0 1 0 0)
  2000.                         (list 0 0 1 0)
  2001.                         (list 0 0 0 1) 
  2002.                          )
  2003.             )
  2004.             
  2005.             
  2006. ;; implement arbitray axis algorithm
  2007.  
  2008.             (progn
  2009.             
  2010.             (if    (and    (< (abs (cadr (assoc 210 s))) (/ 1.0000 64))
  2011.                     (< (abs (caddr (assoc 210 s))) (/ 1.0000 64))
  2012.                 )
  2013.  
  2014.                 (setq x_axis (scale_to_1 (cross_p (list 0 1 0) (cdr (assoc 210 s)))))
  2015.                 (setq x_axis (scale_to_1 (cross_p (list 0 0 1) (cdr (assoc 210 s)))))
  2016.             )
  2017.  
  2018.             (setq temp_matrix 
  2019.  
  2020.  
  2021.                 (list
  2022.                     (append x_axis (list 0))
  2023.                     (append (scale_to_1 (cross_p (cdr (assoc 210 s)) x_axis)) (list 0))
  2024.                     (append (cdr (assoc 210 s)) (list 0))
  2025.                     (list     0 0 0 1)                          (caddr (assoc 10 s))
  2026.                 
  2027.                 )
  2028.  
  2029.             )
  2030.             )  ;close progn                
  2031.  
  2032.  
  2033.         ) ; close if
  2034.         
  2035.  
  2036.         (setq temp_matrix (m_translate temp_matrix))
  2037.         (setq temp_matrix (m_scale temp_matrix))
  2038.  
  2039.  
  2040. ;;  now determine if "INSERT" has been rotated.  If it has apply the rotation
  2041. ;;  matrix.
  2042.  
  2043.         
  2044.         (if    (/= (cdr (assoc 50 s)) 0)
  2045.             (setq temp_matrix (m_rotate temp_matrix (cdr (assoc 50 s))))
  2046.         )
  2047.  
  2048. ;;  scale & translate
  2049.  
  2050.  
  2051.  
  2052.  
  2053. ;;
  2054. ;;  now determine if this is a nested block-- e.g. if a transform exists already.
  2055. ;;  apply it if it does.
  2056. ;;
  2057.                 
  2058.  
  2059.  
  2060.         (if    trans_matrix
  2061.             
  2062.             (setq temp_matrix (m_multiply trans_matrix temp_matrix))
  2063.             
  2064.             
  2065.         )
  2066.                 
  2067. ;;
  2068. ;;    call v_main again with new parameters
  2069. ;;
  2070.                         
  2071.         (v_main
  2072.  
  2073.         (1+ b_flag)
  2074.         (cdr (assoc -2 (tblsearch "block" (cdr (assoc 2 s)))))
  2075.         temp_matrix
  2076.         (* s_factor (abs (cdr (assoc 41 s))))
  2077.         (smooth_entity)
  2078.         (cdr (assoc 8 s)) 
  2079.  
  2080.         )
  2081.         
  2082.         )
  2083.         
  2084.         
  2085.         
  2086.         )
  2087.         
  2088. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2089. ;; studio structure -- only take first one encountered
  2090. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2091.  
  2092.             (
  2093.             (and     (= (cdr (assoc 0 s)) "INSERT") 
  2094.                 (= (cdr (assoc 2 s)) "V_STUDIO")
  2095.                 (not v_studio_list) ;only one studio structure allowed
  2096.                 (check_layer block_layer)  ;layer thawed and on
  2097.                 (= (cdr (assoc 66 s)) 1)  ;attributes must follow    
  2098.                 
  2099.             )
  2100.             (progn
  2101.  
  2102.                 (setq e (entnext e)) 
  2103.                 (setq s (entget e (list "VIVID_RJH")))
  2104.                 (while                
  2105.                     (= (cdr (assoc 0 s)) "ATTRIB")
  2106.  
  2107.  
  2108.                     (if    (or     (= (cdr (assoc 2 s)) "NO_EXP_TRANS")
  2109.                             (= (cdr (assoc 2 s)) "NO_SHADOWS")                        
  2110.                             (= (cdr (assoc 2 s)) "JITTER")                        
  2111.                             (= (cdr (assoc 2 s)) "CAUSTICS")
  2112.                          )
  2113.  
  2114.                          (if     (or (= (cdr (assoc 1 s)) "Y") 
  2115.                              (= (cdr (assoc 1 s)) "YES" )
  2116.                              (= (cdr (assoc 1 s)) "y" )
  2117.                              (= (cdr (assoc 1 s)) "yes" )
  2118.                                  )
  2119.                                                       
  2120.                             (setq v_studio_list
  2121.                                     (cons
  2122.                                     (strcat
  2123.                                         (strcase (cdr (assoc 2 s)) T)
  2124.                                         " "
  2125.                                           
  2126.                                     )
  2127.                                     v_studio_list
  2128.                                     )
  2129.                             )
  2130.  
  2131.                         ) ; close if
  2132.  
  2133.                         
  2134.  
  2135.                         (setq v_studio_list
  2136.                                 (cons
  2137.                                 (strcat
  2138.                                     (strcase (cdr (assoc 2 s)) T)
  2139.                                     " "
  2140.                                     (strcase (cdr (assoc 1 s)) T)
  2141.                                     " "
  2142.                                 )
  2143.                                 v_studio_list
  2144.                                 )
  2145.                         )
  2146.                     ) ; close if
  2147.  
  2148.                     (setq e (entnext e))
  2149.                     (setq s (entget e (list "VIVID_RJH")))
  2150.                 )
  2151.                                             
  2152.             )                            
  2153.                           
  2154.  
  2155.             )
  2156.  
  2157.  
  2158. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2159.         )  ;close cond
  2160.         
  2161.         (setq e (entnext e))  ;get next element in list
  2162.     
  2163.     )
  2164. )
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2174. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2175. ;; end of v_main routine
  2176.  
  2177.  
  2178.  
  2179. ;;
  2180. ;; check_layer
  2181. ;;
  2182. ;; routine returns T if layer is thawed and on, nil otherwise.  It determines
  2183. ;; this by making sure it has an entry in the list "master".  It also sets
  2184. ;; the global variable "old" to this entry.
  2185. ;;
  2186. ;; layer "0" is treated differently-- if encountered an we are processing a
  2187. ;; block-- the layer name used is the one for the block, not 0.  This permits
  2188. ;; processing of transparent blocks-- (needed for processing AME models)
  2189. ;;
  2190.  
  2191. (princ ".")
  2192. (defun check_layer ( block_layer / temp)
  2193.  
  2194.     
  2195.  
  2196.     (if    (= (setq temp (strip_dependent (cdr (assoc 8 s)))) "0")
  2197.  
  2198.         (if
  2199.             block_layer
  2200.             (setq old (assoc (strip_dependent block_layer) master))
  2201.             (setq old (assoc "0" master))
  2202.         )
  2203.         
  2204.         (setq old (assoc temp master))
  2205.     )
  2206.  
  2207. )
  2208.  
  2209.  
  2210.  
  2211. ;*
  2212. ;*  strip_dependent
  2213. ;*
  2214. ;*  strip out dependent layer stuff for xrefs-- only
  2215. ;*  use stuff to the right of last "|"
  2216. ;*
  2217. ;*  if more than eight characters-- only take the first eight
  2218. ;*
  2219. (princ ".")
  2220. (defun strip_dependent (layer1 / temp1 temp2 no_bar)
  2221.  
  2222.     (setq temp1 (strlen layer1))
  2223.     (setq no_bar T)
  2224.     
  2225.     (while     (and     (> temp1 0)
  2226.             no_bar
  2227.         )
  2228.  
  2229.  
  2230.         (if    (= (substr layer1 temp1 1) "|")
  2231.  
  2232.  
  2233.             
  2234.             (progn
  2235.                 (setq no_bar nil)
  2236.                 (setq temp2 (- (strlen layer1) temp1))
  2237.  
  2238.                 (if    (> temp2 8)
  2239.                     (setq temp2 8)
  2240.                 )
  2241.                   
  2242.                 
  2243.             )
  2244.     
  2245.             (setq temp1 (1- temp1))
  2246.  
  2247.         )
  2248.  
  2249.     )
  2250.  
  2251.     (if     no_bar
  2252.  
  2253.         (eval layer1)
  2254.         (substr layer1 (1+ temp1) temp2)
  2255.  
  2256.     )
  2257.  
  2258. )
  2259.     
  2260.  
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270. ;;
  2271. ;;
  2272. ;;  Routine to draw "3dmesh".  Mesh is represented as an array of M X N vertices.
  2273. ;;  Each mesh "box" may be four sided or three sided-- four sided boxes may not 
  2274. ;;  be coplanar.
  2275. ;;
  2276. ;;  Mesh is either translated into smooth patches or faceted polygons depending
  2277. ;;  on the states of variables block_smooth and mesh_smooth.  If either is T
  2278. ;;  the mesh is smoothed.
  2279. ;;
  2280. ;;
  2281.  
  2282. (princ ".")
  2283. (defun draw_mesh (trans_matrix)
  2284.  
  2285. ; first save 70 flag (to determine later if mesh is closed in M or N directions)
  2286. ; and number of M, N.
  2287.  
  2288.     (setq save_70 (cdr (assoc 70 s)))
  2289.     (setq num_m (cdr (assoc 71 s)))
  2290.     (setq save_m num_m)
  2291.     (setq num_n (cdr (assoc 72 s)))
  2292.     (setq save_n num_n)
  2293.  
  2294.     (setq mesh_list (list nil))
  2295.     (setq patch_list nil)
  2296.     (setq normal_list nil)
  2297.  
  2298.  
  2299.     (while (> num_m 0)
  2300.         (setq n_list (list nil))    
  2301.  
  2302.         (while (> num_n 0)
  2303.             
  2304.             (setq e (entnext e))
  2305.             (setq s (entget e (list "VIVID_RJH")))
  2306.             (setq n_list (cons (cdr (assoc 10 s)) n_list))
  2307.             (setq num_n (1- num_n))
  2308.         )
  2309.  
  2310.         
  2311.         ;; if mesh is closed in n direction add one additional point
  2312.  
  2313.         (if (= (boole 1 32 save_70) 32)
  2314.             
  2315.             (setq n_list (cons (nth (1- save_n) n_list) n_list))
  2316.         )
  2317.  
  2318.         (reverse n_list)
  2319.         (setq mesh_list (cons n_list mesh_list))
  2320.         (setq num_n save_n)            ;restore N count
  2321.         (setq num_m (1- num_m))            ;decrement M
  2322.     )        
  2323.     
  2324. ;; if mesh is closed in m direction add one additional list
  2325.  
  2326.         (if     (= (boole 1 1 save_70) 1)
  2327.             (progn
  2328.               (setq mesh_list (cons (nth (1- save_m) mesh_list) mesh_list))
  2329.               (setq save_m (1+ save_m))  ; increment for 1 element
  2330.             )
  2331.         )
  2332.  
  2333.  
  2334. ;; if closed in n direction bump save_n to indicate additional element
  2335.  
  2336.         (if     (= (boole 1 32 save_70) 32)
  2337.             (setq save_n (1+ save_n))
  2338.         )
  2339.  
  2340. ;; now read mesh_list
  2341.  
  2342.     (setq num_m 0)
  2343.     (setq num_n 0)
  2344.  
  2345.     (reverse mesh_list)        
  2346.     (while (< num_m (1- save_m))
  2347.  
  2348.         
  2349.         
  2350.         (while (< num_n (1- save_n))
  2351.  
  2352.             
  2353.             (setq a (nth num_n (nth num_m mesh_list)))
  2354.             (setq b (nth (1+ num_n) (nth num_m mesh_list)))
  2355.             (setq c (nth (1+ num_n) (nth (1+ num_m) mesh_list)))
  2356.             (setq d (nth num_n (nth (1+ num_m) mesh_list)))
  2357.  
  2358.  
  2359.  
  2360.             (if     (smoothed)
  2361.                 (triangulate a b c d trans_matrix)
  2362.                 (draw_3or4 a b c d trans_matrix)
  2363.             )
  2364.             
  2365.             (setq num_n (1+ num_n))
  2366.         )
  2367.  
  2368.         (setq num_n 0)
  2369.         (setq num_m (1+ num_m))
  2370.         
  2371.  
  2372.     )
  2373.      (if    (smoothed)
  2374.         (progn
  2375.  
  2376.                ;(avg_normals)    
  2377.  
  2378. ;            (SETQ DEBUG_START (GETVAR "DATE"))
  2379.  
  2380.             (draw_patch)
  2381.  
  2382. ;            (SETQ DEBUG_END (GETVAR "DATE"))
  2383. ;            (SETQ  CTR4 (+ CTR4 (* 86400.00 (- DEBUG_END DEBUG_START))))
  2384.  
  2385.         )
  2386.     )
  2387.  
  2388.  
  2389. )        
  2390.  
  2391. ;;
  2392. ;;    triangulate -- routine called by draw_mesh.  Takes four points
  2393. ;;    of a polygon mesh "box" and breaks them into one or two triangular
  2394. ;;    patches.  For smooth meshes only.
  2395.  
  2396.  
  2397. (princ ".")
  2398. (defun triangulate (a b c d trans_matrix)
  2399.     
  2400.     (setq 3dmesh_p_count (1+ 3dmesh_p_count))
  2401.  
  2402.     
  2403.     (if (equal a b 0.001)
  2404.         (add_patch b c d trans_matrix)
  2405.         (if  (equal b c 0.001)
  2406.          (add_patch c d a trans_matrix)
  2407.          (if  (equal c d 0.001)
  2408.               (add_patch d a b trans_matrix)
  2409.               (if  (equal d a 0.001)
  2410.                (add_patch a b c trans_matrix)
  2411.                  (progn
  2412.                     (setq 3dmesh_p_count (1+ 3dmesh_p_count))
  2413.                     (add_patch a b c trans_matrix)
  2414.                     (add_patch a c d trans_matrix)
  2415.                 )
  2416.                 
  2417.             )
  2418.           )
  2419.         )
  2420.     )
  2421.  
  2422. )    
  2423.  
  2424. ;;
  2425. ;;    function draw_3or4 -- routine called by draw_mesh.  Takes four points
  2426. ;;    of a polygon mesh "box" and determines if any two of the points are
  2427. ;;    identical.   If they are, a three sides 3dmesh is drawn.  If not the
  2428. ;;    routine determines if the four points are coplanar-- if they are a
  2429. ;;    four-sided 3dmesh is drawn-- if not the "mesh box" is split into two
  2430. ;;    triangular 3dmeshes. For faceted meshes only.
  2431.  
  2432.  
  2433.  
  2434. (princ ".")
  2435. (defun draw_3or4 (a b c d trans_matrix)
  2436.     
  2437.     (setq f_3dmesh_p_count (1+ f_3dmesh_p_count))
  2438.  
  2439.     
  2440.     (if (equal a b 0.001)
  2441.         (draw_3 b c d trans_matrix)
  2442.         (if  (equal b c 0.001)
  2443.          (draw_3 c d a trans_matrix)
  2444.          (if  (equal c d 0.001)
  2445.               (draw_3 d a b trans_matrix)
  2446.               (if  (equal d a 0.001)
  2447.                (draw_3 a b c trans_matrix)
  2448.                (if
  2449.                 (inters a c b d T)  ;are points coplanar?
  2450.                 (draw_4 a b c d trans_matrix)
  2451.                 (progn
  2452.                     (setq f_3dmesh_p_count (1+ f_3dmesh_p_count))
  2453.                     (draw_3 a b c trans_matrix)
  2454.                     (draw_3 a c d trans_matrix)
  2455.                 )
  2456.                 )
  2457.             )
  2458.           )
  2459.         )
  2460.     )
  2461.  
  2462. )    
  2463.  
  2464.  
  2465.  
  2466.  
  2467.  
  2468.  
  2469.  
  2470.  
  2471. ;;
  2472. ;;  draw_3 - routine adds 3 sided polygon to "master" structure
  2473. ;;
  2474. (princ ".")
  2475. (defun draw_3 (a b c trans_matrix)
  2476.  
  2477. ;; translate points first if this is a block
  2478.  
  2479.     (if    trans_matrix
  2480.         (progn
  2481.         (setq a (MCS_to_WCS a trans_matrix))
  2482.         (setq b (MCS_to_WCS b trans_matrix))
  2483.         (setq c (MCS_to_WCS c trans_matrix))
  2484.         )
  2485.     )
  2486.  
  2487.  
  2488.  
  2489.     (setq new
  2490.         (cons
  2491.             (car old)
  2492.             (list
  2493.              (cons             
  2494.             (strcat 
  2495.             "polygon {points 3 vertex "
  2496.             (rtos (car  a) 2 6)
  2497.             " "
  2498.             (rtos (cadr a) 2 6)
  2499.             " "
  2500.             (rtos (caddr a) 2 6)
  2501.             " vertex "
  2502.             (rtos (car b) 2 6)
  2503.             " "
  2504.             (rtos (cadr  b) 2 6)
  2505.             " "
  2506.             (rtos (caddr b) 2 6)
  2507.             " vertex "
  2508.             (rtos (car c) 2 6)
  2509.             " "
  2510.             (rtos (cadr c) 2 6)
  2511.             " "
  2512.             (rtos (caddr c) 2 6)
  2513.             
  2514.             "  }"
  2515.             )
  2516.             (cadr old)
  2517.             ))
  2518.             )
  2519.             )
  2520.     
  2521.  
  2522.     (setq master (subst new old master))
  2523.     (setq old new)
  2524. )
  2525.                 
  2526.  
  2527. ;;
  2528. ;; draw_4 -- adds 4 sided polygon to "master" structure
  2529. ;;
  2530. (princ ".")
  2531. (defun draw_4 (a b c d trans_matrix)
  2532.  
  2533. ;; translate points first if this is a block.
  2534.  
  2535.     (if
  2536.         trans_matrix
  2537.         
  2538.         (progn
  2539.         (setq a (MCS_to_WCS a trans_matrix))
  2540.         (setq b (MCS_to_WCS b trans_matrix))
  2541.         (setq c (MCS_to_WCS c trans_matrix))
  2542.         (setq d (MCS_to_WCS d trans_matrix))        
  2543.         )
  2544.     )
  2545.  
  2546.  
  2547.     (setq new
  2548.         (cons
  2549.             (car old)
  2550.             (list
  2551.              (cons             
  2552.             (strcat 
  2553.             "polygon {points 4 vertex "
  2554.             (rtos (car  a) 2 6)
  2555.             " "
  2556.             (rtos (cadr a) 2 6)
  2557.             " "
  2558.             (rtos (caddr a) 2 6)
  2559.             " vertex "
  2560.             (rtos (car b) 2 6)
  2561.             " "
  2562.             (rtos (cadr b) 2 6)
  2563.             " "
  2564.             (rtos (caddr b) 2 6)
  2565.             "  vertex "
  2566.             (rtos (car c) 2 6)
  2567.             " "
  2568.             (rtos (cadr c) 2 6)
  2569.             " "
  2570.             (rtos (caddr c) 2 6)
  2571.             " vertex "
  2572.             (rtos (car d) 2 6)
  2573.             " "
  2574.             (rtos (cadr d) 2 6)
  2575.             " "
  2576.             (rtos (caddr d) 2 6)
  2577.             " }"
  2578.             )
  2579.             (cadr old)
  2580.             ))
  2581.         )
  2582.     )
  2583.     
  2584.     
  2585.     (setq master (subst new old master))
  2586.     (setq old new)
  2587. )                
  2588.  
  2589.  
  2590.  
  2591. ;;
  2592. ;;  cross_p return a cross product of two vectors (u X v) expressed as three
  2593. ;;  element lists
  2594. ;;
  2595. (princ ".")
  2596. (defun cross_p (u v)
  2597.  
  2598.     (list
  2599.  
  2600.         (- (* (nth 1 u) (nth 2 v)) (* (nth 1 v) (nth 2 u)))
  2601.         (- (* (nth 2 u) (nth 0 v)) (* (nth 2 v) (nth 0 u)))
  2602.         (- (* (nth 0 u) (nth 1 v)) (* (nth 0 v) (nth 1 u)))
  2603.     )
  2604. )
  2605.  
  2606. ;;
  2607. ;;  cell_i_j returns the value of a matrix element specified by (row i, col j)
  2608. ;;
  2609. (princ ".")
  2610. (defun cell_i_j (matrix1 i j)
  2611.  
  2612.     (nth (1- i) (nth (1- j) matrix1))
  2613. )
  2614.  
  2615.  
  2616. ;;
  2617. ;;  dot_i_j  returns the dot product of row (i), matrix1  and column (j), matrix2
  2618. ;;  this is an intermediate step in performing matrix multiplication.
  2619. ;;
  2620. (princ ".")
  2621. (defun dot_i_j (matrix1 matrix2 i j)
  2622.  
  2623.  
  2624.     (+
  2625.     (* (cell_i_j matrix1 i 1) (cell_i_j matrix2 1 j))
  2626.     (* (cell_i_j matrix1 i 2) (cell_i_j matrix2 2 j))
  2627.     (* (cell_i_j matrix1 i 3) (cell_i_j matrix2 3 j))
  2628.     (* (cell_i_j matrix1 i 4) (cell_i_j matrix2 4 j))
  2629.     )
  2630. )
  2631.  
  2632. ;;
  2633. ;; m_multiply -- multiply matrix1 . matrix2-- (must be 4 x 4 matrices).  Resulting
  2634. ;; 4 x 4 matrix is returned and also stored globally in m_result.
  2635. ;;
  2636. (princ ".")
  2637. (defun m_multiply (matrix1 matrix2 / col_count row_count col_list)
  2638.  
  2639.     (setq m_result nil)
  2640.     (setq col_count 1)
  2641.     (while    (<= col_count 4)
  2642.  
  2643.         (setq col_list nil)
  2644.         (setq row_count 1)
  2645.  
  2646.         (while    (<= row_count 4)
  2647.  
  2648.  
  2649.             (setq col_list
  2650.                 (cons
  2651.                 (dot_i_j matrix1 matrix2 row_count col_count)
  2652.                 col_list
  2653.                 )
  2654.             )
  2655.  
  2656.                         
  2657.             (setq row_count (1+ row_count))
  2658.         )
  2659.         (setq col_list (reverse col_list))
  2660.         
  2661.         (setq m_result (cons col_list m_result))
  2662.         (setq col_count (1+ col_count))
  2663.     )
  2664.     (setq m_result (reverse m_result))
  2665. )
  2666.  
  2667. ;;
  2668. ;; m_rotate- apply a rotational transform about the z axis to the specified matrix.
  2669. ;; Returns transformed matrix-- uses m_multiply. Theta is in radians.
  2670. ;;
  2671. ;; This routine is used to rotate a block's coordinate system if the block has
  2672. ;; either been inserted with a rotation angle or subsequently rotated about
  2673. ;; its own z-axis.  It is a piece of the process of translating from a block's
  2674. ;; coordinate system to the WCS.
  2675. ;;
  2676. (princ ".")
  2677.  
  2678. (defun m_rotate (matrix1 theta)
  2679.  
  2680.     (m_multiply
  2681.  
  2682. ;; rotational transform matrix
  2683.  
  2684.         matrix1
  2685.  
  2686.         (list
  2687.         (list (cos theta) (sin theta) 0 0)
  2688.         (list (- (sin theta))  (cos theta) 0 0)
  2689.         (list 0 0 1 0)
  2690.         (list 0 0 0 1)
  2691.         )
  2692.         
  2693. ;;
  2694.  
  2695.     )
  2696. )
  2697. ;;
  2698. ;;  m_scale -- apply scalar transform
  2699. ;;
  2700. (princ ".")
  2701. (defun m_scale (matrix1)
  2702.  
  2703.     (m_multiply
  2704.  
  2705.         matrix1
  2706.  
  2707.         (list
  2708.  
  2709.             (list (cdr (assoc 41 s)) 0 0 0)
  2710.             (list 0 (cdr (assoc 42 s)) 0 0)
  2711.             (list 0 0 (cdr (assoc 43 s)) 0)
  2712.             (list 0 0 0 1)
  2713.         )
  2714.     )
  2715. )
  2716.  
  2717. ;;
  2718. ;;  m_translate -- apply translation transform
  2719. ;;
  2720. (princ ".")
  2721. (defun m_translate (matrix1)
  2722.  
  2723.     (m_multiply
  2724.  
  2725.         matrix1
  2726.  
  2727.         (list
  2728.  
  2729.             (list 1 0 0 0)
  2730.             (list 0 1 0 0)
  2731.             (list 0 0 1 0)
  2732.             (list     (cadr (assoc 10 s))
  2733.                 (caddr (assoc 10 s))
  2734.                 (cadddr (assoc 10 s))
  2735.                 1
  2736.             )
  2737.         )
  2738.  
  2739.     )
  2740. )
  2741.                 
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747. ;;
  2748. ;;
  2749. ;;  MCS_to_WCS - This routine transforms a single point from the coordinate
  2750. ;;  system of a block's entities (Model Coordinate System) to the WCS.  It
  2751. ;;  works by making use of the transformation matrix constructed based on
  2752. ;;  a particular INSERT's extrusion vector, scale factors, and rotation angle--
  2753. ;;  plus the transformation matrix of the parent block if this is a child
  2754. ;;  (nested) block.  (It is equivalent to the process described by AutoLISP's
  2755. ;;  nentsel command.)  This matrix is passed to the main routine "v_main" as
  2756. ;;  a parameter "matrix1".
  2757. ;;
  2758. ;;
  2759. (princ ".")
  2760. (defun MCS_to_WCS (a matrix1)
  2761.  
  2762.     (list
  2763.  
  2764.         (+    (* (cell_i_j matrix1 1 1) (car a))
  2765.             (* (cell_i_j matrix1 1 2) (cadr a))
  2766.             (* (cell_i_j matrix1 1 3) (caddr a))
  2767.             (cell_i_j matrix1 1 4)
  2768.         )
  2769.  
  2770.  
  2771.         (+    (* (cell_i_j matrix1 2 1) (car a))
  2772.             (* (cell_i_j matrix1 2 2) (cadr a))
  2773.             (* (cell_i_j matrix1 2 3) (caddr a))
  2774.             (cell_i_j matrix1 2 4)        
  2775.         )
  2776.  
  2777.         (+    (* (cell_i_j matrix1 3 1) (car a))
  2778.             (* (cell_i_j matrix1 3 2) (cadr a))
  2779.             (* (cell_i_j matrix1 3 3) (caddr a))
  2780.             (cell_i_j matrix1 3 4)
  2781.         )
  2782.         
  2783.     )
  2784. )
  2785.  
  2786. ;(defun MCS_to_WCS_n (a matrix1)
  2787. ;
  2788. ;    (list
  2789. ;
  2790. ;        (+    (* (cell_i_j matrix1 1 1) (car a))
  2791. ;            (* (cell_i_j matrix1 1 2) (cadr a))
  2792. ;            (* (cell_i_j matrix1 1 3) (caddr a))
  2793. ;            
  2794. ;        )
  2795. ;
  2796. ;
  2797. ;        (+    (* (cell_i_j matrix1 2 1) (car a))
  2798. ;            (* (cell_i_j matrix1 2 2) (cadr a))
  2799. ;            (* (cell_i_j matrix1 2 3) (caddr a))
  2800. ;            
  2801. ;        )
  2802. ;
  2803. ;        (+    (* (cell_i_j matrix1 3 1) (car a))
  2804. ;            (* (cell_i_j matrix1 3 2) (cadr a))
  2805. ;            (* (cell_i_j matrix1 3 3) (caddr a))
  2806. ;            
  2807. ;        )
  2808. ;        
  2809. ;    )
  2810. ;)
  2811. ;
  2812. ;
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822. ;;
  2823. ;;  scale_to_1 -- routine which will take an axis and scale it to unit length
  2824. ;;  if it is not already.  This is part of implementing AutoCAD's Arbitrary
  2825. ;;  Axis Algorithm documented in Appendix C of the manual.
  2826. ;;
  2827. (princ ".")
  2828. (defun scale_to_1 (axis)
  2829.  
  2830.     (if    (not (equal (setq temp     (+
  2831.                     (* (car axis) (car axis))
  2832.                     (* (cadr axis) (cadr axis))
  2833.                     (* (caddr axis) (caddr axis))
  2834.                     )
  2835.                  )
  2836.                  1
  2837.                  0.0001
  2838.             )
  2839.         )
  2840.  
  2841.  
  2842.         (progn    (setq temp (sqrt (/ 1.000 temp)))
  2843.             (list
  2844.                 (* (car axis) temp)
  2845.                 (* (cadr axis) temp)
  2846.                 (* (caddr axis) temp)
  2847.             )
  2848.         )
  2849.  
  2850.         (setq temp axis)
  2851.         
  2852.     )
  2853. )
  2854.         
  2855.  
  2856. ;;
  2857. ;; print_count -- prints entity counter and updates it
  2858. ;;
  2859. (princ ".")
  2860. (defun print_count ()
  2861.  
  2862.     (princ "\r")
  2863.     (prin1 (setq main_count (1+ main_count)))
  2864.  
  2865. )
  2866.  
  2867. ;;
  2868. ;; add_patch    add a triangular patch to the patch_list for later manipulation.
  2869. ;;         add surface normals for each vertex to normal_list
  2870. ;;        First translate from MCS to WCS if this is a block.
  2871. (princ ".")
  2872. (defun add_patch (a b c trans_matrix)
  2873.  
  2874.     (if    trans_matrix
  2875.         (progn
  2876.             (setq a (MCS_to_WCS a trans_matrix))
  2877.             (setq b (MCS_to_WCS b trans_matrix))
  2878.             (setq c (MCS_to_WCS c trans_matrix))
  2879.         )
  2880.     )
  2881.  
  2882. ;    (SETQ DEBUG_START (GETVAR "DATE"))
  2883.  
  2884.     (setq normal1 (calc_normal a b c))  ;calculate surface normal
  2885.  
  2886. ;; convert vertices to strings for use in association lists
  2887.  
  2888.     (setq a (real_to_string a))
  2889.     (setq b (real_to_string b))
  2890.     (setq c (real_to_string c))
  2891.  
  2892. ;    (SETQ DEBUG_END (GETVAR "DATE"))
  2893. ;    (SETQ  CTR1 (+ CTR1 (* 86400.00 (- DEBUG_END DEBUG_START))))
  2894.     
  2895.      
  2896. ;    (SETQ DEBUG_START (GETVAR "DATE"))
  2897.  
  2898.     (setq patch_list 
  2899.     (cons 
  2900.     (list (add_normal a) (add_normal b) (add_normal c))
  2901.     patch_list
  2902.     )
  2903.     ) 
  2904.  
  2905. ;    (SETQ DEBUG_END (GETVAR "DATE"))
  2906. ;    (SETQ  CTR3 (+ CTR3 (* 86400.00 (- DEBUG_END DEBUG_START))))
  2907.  
  2908.  
  2909. )
  2910. ;;
  2911. ;; add_normal
  2912. ;;
  2913. ;; add a normal to the normal_list, a list which is keyed by vertex.  If
  2914. ;; a normal or normals are already present for this vertex, average in the new
  2915. ;; normal (found in global variable "normal1") to the list.
  2916. ;; 
  2917. ;;
  2918. (princ ".")
  2919. (defun add_normal (vertex / old_normals)
  2920.  
  2921.     (if
  2922.         (setq old_normals (assoc vertex normal_list))
  2923.  
  2924.  
  2925.         ;; vertex exists in normal list-- average in new normal, return
  2926.         ;; index value
  2927.         
  2928.            (progn
  2929.  
  2930.         (setq vertex_count (cadr old_normals))
  2931.  
  2932.         (setq normal_list
  2933.  
  2934.         (subst
  2935.         
  2936.             (list
  2937.             vertex
  2938.             (1+ vertex_count)
  2939.             (mapcar '(lambda (x y)
  2940.                 (/ (+ (* x vertex_count) y) (1+ vertex_count))
  2941.                 )
  2942.                 (caddr old_normals)
  2943.                 normal1
  2944.  
  2945.             ); close mapcar
  2946.             
  2947.             (cadddr old_normals)
  2948.             ); close list            
  2949.         
  2950.             old_normals
  2951.             
  2952.             normal_list
  2953.         )
  2954.         ); close setq
  2955.  
  2956.         (cadddr old_normals)  ;return index value
  2957.         ); close progn
  2958.  
  2959.  
  2960.         ;; vertex not found, add to list w/ new index value
  2961.  
  2962.         (progn
  2963.         (setq normal_list
  2964.             (cons (list vertex 1 normal1 normal_index) normal_list)
  2965.         )
  2966.         (setq normal_index (1+ normal_index))
  2967.         (1- normal_index)            ;return index value
  2968.         ) ; close progn
  2969.     ); close if
  2970.  
  2971.  
  2972. )        
  2973. ;;
  2974. ;; calculate surface normal based on formula for plane
  2975. ;;
  2976. (princ ".")
  2977. (defun calc_normal (a b c)
  2978.  
  2979.     (list
  2980.         (+     (* (cadr a) (- (caddr b) (caddr c)))
  2981.                    (* (cadr b) (- (caddr c) (caddr a)))
  2982.             (* (cadr c) (- (caddr a) (caddr b)))
  2983.         )
  2984.         (+    (* (caddr a) (- (car b) (car c)))
  2985.             (* (caddr b) (- (car c) (car a)))
  2986.             (* (caddr c) (- (car a) (car b)))
  2987.         )
  2988.         (+     (* (car a) (- (cadr b) (cadr c)))
  2989.             (* (car b) (- (cadr c) (cadr a)))
  2990.             (* (car c) (- (cadr a) (cadr b)))
  2991.         )
  2992.     )
  2993. )
  2994.  
  2995. ;;
  2996. ;; avg_normals
  2997. ;;
  2998. ;; steps through normal_list which is a table of vertices and their assoc.
  2999. ;; normals for a given mesh-- and averages them.  At the conclusion of
  3000. ;; the routine, normal_list is reconstructed with only one normal per
  3001. ;; vertex (an average of the old ones)
  3002. ;;
  3003. (princ ".")
  3004. (defun avg_normals (/ temp1 temp2 temp3)
  3005.  
  3006.     (SETQ DEBUG_START (GETVAR "DATE"))
  3007.     
  3008.  
  3009.     (setq temp1 normal_list)
  3010.     (setq temp2 0)
  3011.     (setq temp3 (length normal_list))
  3012.  
  3013.     (while
  3014.         
  3015.         (< temp2 temp3)
  3016.         (if
  3017.             (> 2 (length (car temp1))) ;skip if only one normal
  3018.  
  3019.             (setq normal_list
  3020.                 (subst
  3021.                     (average (car temp1))  ;average norms
  3022.                     (car temp1)
  3023.                     normal_list
  3024.                 )
  3025.             )
  3026.         )
  3027.  
  3028.         (setq temp1 (cdr temp1))
  3029.         (setq temp2 (1+ temp2))
  3030.  
  3031.     )
  3032.  
  3033.     (SETQ DEBUG_END (GETVAR "DATE"))
  3034.     (SETQ  CTR2 (+ CTR2 (* 86400.00 (- DEBUG_END DEBUG_START))))
  3035.  
  3036.  
  3037. )            
  3038. ;;
  3039. ;;  average.  
  3040. ;;
  3041. ;;  average one element of normal_list.  Each element consists of a vertex
  3042. ;;  key-- this is left unchanged-- followed by 2 or more normal vectors--
  3043. ;;  these are averaged.
  3044. ;;
  3045. (princ ".")
  3046. (defun average (norms / temp1 temp2)
  3047.  
  3048.     (setq temp2 (list 0 0 0))
  3049.     (setq temp1 1)
  3050.  
  3051.     ;; first accumulate sum in temp2
  3052.  
  3053.     (while
  3054.  
  3055.         (< temp1 (length norms))
  3056.  
  3057.         (setq temp2
  3058.  
  3059.             (list
  3060.                 (+ (car temp2) (car (nth temp1 norms)))
  3061.                 (+ (cadr temp2) (cadr (nth temp1 norms)))
  3062.                 (+ (caddr temp2) (caddr (nth temp1 norms)))
  3063.             )
  3064.         )
  3065.  
  3066.         (setq temp1 (1+ temp1))
  3067.  
  3068.     )
  3069.  
  3070.     ;; now divide by number of norms
  3071.  
  3072.     (setq norms
  3073.  
  3074.         (list
  3075.  
  3076.             (car norms)
  3077.             (mapcar    '(lambda (x)
  3078.                 (/ x (1- (length norms)))
  3079.                 )
  3080.                 temp2
  3081.             )
  3082.         )
  3083.     )
  3084. )
  3085.         
  3086. ;;
  3087. ;;  draw_patch
  3088. ;;
  3089. ;;  step through patch_list and output each patch
  3090. ;;  write triangular patches with explicit surface normals to "master".
  3091. ;;
  3092.  
  3093. (princ ".")
  3094.  
  3095. (defun draw_patch (/ temp1 temp2 temp3 patch)
  3096.  
  3097.     (setq normal_list (reverse normal_list))
  3098.     (setq temp1 (list " "))
  3099.     (setq temp2 0)
  3100.     (setq patch (nth temp2 patch_list))
  3101.     (setq temp3 (length patch_list))
  3102.  
  3103.     (repeat temp3
  3104. ;    (foreach patch patch_list
  3105.  
  3106.         (setq temp1
  3107.  
  3108.               (cons
  3109.  
  3110.             (strcat
  3111.             "patch {"
  3112.             "vertex "
  3113.             (car (nth (car patch) normal_list))
  3114.             " normal "
  3115.             (real_to_string (caddr (nth (car patch) normal_list)))
  3116.             )
  3117.             
  3118.                 (cons            
  3119.  
  3120.                 (strcat
  3121.                 "vertex "
  3122.                 (car (nth (cadr patch) normal_list))
  3123.                 " normal "
  3124.                 (real_to_string (caddr (nth (cadr patch) normal_list)))
  3125.                 )                
  3126.             
  3127.  
  3128.  
  3129.                     (cons    
  3130.         
  3131.                     (strcat
  3132.                     "vertex "
  3133.                     (car (nth (caddr patch) normal_list))
  3134.                     " normal "
  3135.                     (real_to_string (caddr (nth (caddr patch) normal_list)))
  3136.                     " }"
  3137.                     )
  3138.                     
  3139.                     temp1
  3140.             
  3141.                     ) ;close cons
  3142.                 ); close cons
  3143.             ); close cons
  3144.             
  3145.             
  3146.          
  3147.         ) ; setq
  3148.  
  3149.     (setq temp2 (1+ temp2))
  3150.     (setq patch (nth temp2 patch_list))
  3151.  
  3152.     ) ; close repeat
  3153.  
  3154. ;     ) ; close foreach
  3155.  
  3156.  
  3157.     (setq new
  3158.         (cons (car old)
  3159.          (list
  3160.           (append
  3161.  
  3162.             (cadr old)
  3163.             temp1
  3164.         
  3165.           ) 
  3166.          ) 
  3167.         ) 
  3168.     ) ; close setq
  3169.  
  3170.     (setq master (subst new old master))
  3171.  
  3172. )
  3173.  
  3174.  
  3175. ;;
  3176. ;; real_to_string
  3177. ;;
  3178. ;; converts a set of 3 coordinate points to space delimited ascii using
  3179. ;; AutoLISP's rtos function.
  3180. ;;
  3181. (princ ".")
  3182. (defun real_to_string (real)
  3183.  
  3184.     (strcat
  3185.  
  3186.         (rtos (car real) 2 6)
  3187.         " "
  3188.         (rtos (cadr real) 2 6)
  3189.         " "
  3190.         (rtos (caddr real) 2 6)
  3191.         " "
  3192.             )
  3193. )
  3194.  
  3195.  
  3196. ;;
  3197. ;; smooth_entity 
  3198. ;;
  3199. ;; Determine by searching extended entity data if "smooth" flag is set.
  3200. ;; Return T or nil.
  3201. ;;
  3202. (princ ".")
  3203. (defun smooth_entity (/ temp)
  3204.  
  3205.     (if    (setq temp (assoc -3 s))
  3206.         (if    (setq temp (assoc "VIVID_RJH" (cdr temp)))
  3207.             (if    (setq temp (assoc 1000 (cdr temp)))
  3208.                 (if    (= (cdr temp) "smooth")
  3209.                     (eval T)
  3210.                     
  3211.                 )
  3212.                 
  3213.             )
  3214.             
  3215.             
  3216.         )
  3217.      )
  3218.  
  3219. )
  3220.  
  3221. ;;
  3222. ;; smoothed
  3223. ;;
  3224. ;; returns T if either block_smooth or mesh_smooth flag is set,
  3225. ;; nil otherwise
  3226. ;;
  3227. (princ ".")
  3228. (defun smoothed ()
  3229.  
  3230.     (or    (eval block_smooth)
  3231.         (eval mesh_smooth)
  3232.     )
  3233. )
  3234.  
  3235.  
  3236.  
  3237. ;;***** some additional AutoCAD commands
  3238.  
  3239.  
  3240. ;**********************************************************************
  3241. ;*                                    
  3242. ;*    c:smooth    AutoCAD command to tag either an insert or
  3243. ;*            mesh as "smooth".  If a translator encounters
  3244. ;*            this tag, it will interpret either the mesh
  3245. ;*            or all the meshes within a block definition
  3246. ;*            as triangular patches with interpolated surface
  3247. ;*            normals @ coincident vertices.  
  3248. ;*            Routine uses extended entity data and requires
  3249. ;*            R11 to work properly.
  3250. ;*            Nested blocks will not necessarily have the
  3251. ;*            same tag as parent blocks.
  3252. ;*
  3253. ;***********************************************************************
  3254.  
  3255. (defun c:smooth () 
  3256.  
  3257.     (setq ss (ssget))
  3258.     (setq temp1 0) ;count # smoothed
  3259.     (setq temp 0) ;index into ss
  3260.  
  3261.     (while    (setq e (ssname ss temp))
  3262.         (setq s (entget e (list "VIVID_RJH")))
  3263.  
  3264. ;
  3265. ; only operate on blocks, pface meshes, and 3d meshes.
  3266. ;
  3267.  
  3268.         (if 
  3269.                (or
  3270.  
  3271.                 (= (cdr (assoc 0 s)) "INSERT")    ;block
  3272.             
  3273.                 (and (= (cdr (assoc 0 s)) "POLYLINE") 
  3274.                      (or
  3275.             
  3276.                     (= 64 (boole 1 64 (cdr (assoc 70 s))))
  3277.                     (= 16 (boole 1 16 (cdr (assoc 70 s))))
  3278.                      )
  3279.                 )
  3280.             )
  3281.  
  3282.         (if    (setq ex_list (assoc -3 s))
  3283.             
  3284.             (if    (setq app_list (assoc "VIVID_RJH" (cdr ex_list)))
  3285.  
  3286.                 ;* application "VIVID_RJH" found here
  3287.                 (progn
  3288.                 (setq ed
  3289.                 (subst
  3290.                 (cons
  3291.                 (car ex_list)
  3292.                 (subst
  3293.  
  3294.                     (if    (assoc 1000 (cdr app_list))
  3295.                         ;* 1000 group exists
  3296.                         (cons
  3297.                         (car app_list)
  3298.                         (subst
  3299.                             (cons 1000 "smooth")
  3300.                             (assoc 1000 (cdr app_list))
  3301.                             (cdr app_list)
  3302.                         )
  3303.                         ); close cons
  3304.                         
  3305.  
  3306.                         ;* 1000 group not found
  3307.                         (cons
  3308.                         (car app_list)
  3309.                         (cons (cons 1000 "smooth") (cdr app_list))
  3310.                         )
  3311.                                             
  3312.                     ) ;close if
  3313.  
  3314.                 app_list        
  3315.                 (cdr ex_list)
  3316.                 ) ; close subst
  3317.                 ) ; close cons
  3318.  
  3319.                 ex_list
  3320.                 s
  3321.                 ); close subst
  3322.                 ); close setq
  3323.                 
  3324.                 (entmod ed)
  3325.  
  3326.                 (setq temp1 (1+ temp1)) ;incr. smoothed ctr.
  3327.                 ) ; close progn
  3328.  
  3329.  
  3330.  
  3331.                 ;* application "VIVID_RJH" not found
  3332.                 (progn
  3333.                 (entmod
  3334.                 (subst
  3335.                 (cons
  3336.                 (car ex_list)
  3337.                 (cons
  3338.                           (cons
  3339.                           "VIVID_RJH"
  3340.                           (list (cons 1000 "smooth"))
  3341.                           )
  3342.                     (cdr ex_list)                                
  3343.                 ); close cons
  3344.                 ); close cons
  3345.  
  3346.                 ex_list
  3347.                 s
  3348.                 ); close subst
  3349.                 ); close entmod                    
  3350.  
  3351.                 (setq temp1 (1+ temp1)) ;incr. smoothed ctr.
  3352.                 ) ; close progn
  3353.  
  3354.                    
  3355.             ); close if
  3356.  
  3357.             ;* no extended entity data here
  3358.  
  3359.             (progn
  3360.             (setq ed
  3361.             (cons
  3362.             
  3363.             (list
  3364.                 -3
  3365.                 (list
  3366.                 "VIVID_RJH"
  3367.                 (cons 1000 "smooth")
  3368.                 )
  3369.                             
  3370.             ); close list
  3371.  
  3372.             s
  3373.  
  3374.             ); close cons
  3375.             ); close setq
  3376.             (entmod ed)
  3377.  
  3378.             (setq temp1 (1+ temp1)) ; incr. counter
  3379.             ); close progn
  3380.  
  3381.         ) ; close if
  3382.  
  3383.         ); close if
  3384.  
  3385.         (setq temp (1+ temp)) ;increment index into ss
  3386.  
  3387.     ); close while
  3388.  
  3389.     ;* print statistics
  3390.  
  3391.     (princ "\n")
  3392.     (prin1 temp1)
  3393.     (princ " objects smoothed.")
  3394.     (princ)
  3395.  
  3396.  
  3397. )
  3398.  
  3399. ;**********************************************************************
  3400. ;*                                    
  3401. ;*    c:facet        AutoCAD command to tag either an insert or
  3402. ;*            mesh as "faceted".  Currentyly the translator
  3403. ;*            does not look specifically for this tag-- if it
  3404. ;*            does not find a "smooth" tag, the mesh or all
  3405. ;*            meshes within a block definition will be 
  3406. ;*            translated as polygonally faceted surfaces.
  3407. ;*            Routine uses extended entity data and requires
  3408. ;*            R11 to work properly.
  3409. ;*            Nested blocks will not necessarily have the
  3410. ;*            same tag as parent blocks.
  3411. ;*
  3412. ;***********************************************************************
  3413.  
  3414.  
  3415.  
  3416.  
  3417.  
  3418. (defun c:facet () 
  3419.  
  3420.     (setq ss (ssget))
  3421.     (setq temp1 0) ;count # faceted
  3422.     (setq temp 0) ;index into ss
  3423.  
  3424.     (while    (setq e (ssname ss temp))
  3425.         (setq s (entget e (list "VIVID_RJH")))
  3426.  
  3427. ;
  3428. ; only operate on blocks, pface meshes, and 3d meshes.
  3429. ;
  3430.  
  3431.         (if 
  3432.                (or
  3433.  
  3434.                 (= (cdr (assoc 0 s)) "INSERT")    ;block
  3435.             
  3436.                 (and (= (cdr (assoc 0 s)) "POLYLINE") 
  3437.                      (or
  3438.             
  3439.                     (= 64 (boole 1 64 (cdr (assoc 70 s))))
  3440.                     (= 16 (boole 1 16 (cdr (assoc 70 s))))
  3441.                      )
  3442.                 )
  3443.             )
  3444.  
  3445.         (if    (setq ex_list (assoc -3 s))
  3446.             
  3447.             (if    (setq app_list (assoc "VIVID_RJH" (cdr ex_list)))
  3448.  
  3449.                 ;* application "VIVID_RJH" found here
  3450.                 (progn
  3451.                 (setq ed
  3452.                 (subst
  3453.                 (cons
  3454.                 (car ex_list)
  3455.                 (subst
  3456.  
  3457.                     (if    (assoc 1000 (cdr app_list))
  3458.                         ;* 1000 group exists
  3459.                         (cons
  3460.                         (car app_list)
  3461.                         (subst
  3462.                             (cons 1000 "facet")
  3463.                             (assoc 1000 (cdr app_list))
  3464.                             (cdr app_list)
  3465.                         )
  3466.                         ); close cons
  3467.                         
  3468.  
  3469.                         ;* 1000 group not found
  3470.                         (cons
  3471.                         (car app_list)
  3472.                         (cons (cons 1000 "facet") (cdr app_list))
  3473.                         )
  3474.                                             
  3475.                     ) ;close if
  3476.  
  3477.                 app_list        
  3478.                 (cdr ex_list)
  3479.                 ) ; close subst
  3480.                 ) ; close cons
  3481.  
  3482.                 ex_list
  3483.                 s
  3484.                 ); close subst
  3485.                 ); close setq
  3486.                 
  3487.                 (entmod ed)
  3488.  
  3489.                 (setq temp1 (1+ temp1)) ;incr. faceted ctr.
  3490.                 ) ; close progn
  3491.  
  3492.  
  3493.  
  3494.                 ;* application "VIVID_RJH" not found
  3495.                 (progn
  3496.                 (entmod
  3497.                 (subst
  3498.                 (cons
  3499.                 (car ex_list)
  3500.                 (cons
  3501.                           (cons
  3502.                           "VIVID_RJH"
  3503.                           (list (cons 1000 "facet"))
  3504.                           )
  3505.                     (cdr ex_list)                                
  3506.                 ); close cons
  3507.                 ); close cons
  3508.  
  3509.                 ex_list
  3510.                 s
  3511.                 ); close subst
  3512.                 ); close entmod                    
  3513.  
  3514.                 (setq temp1 (1+ temp1)) ;incr. faceted ctr.
  3515.                 ) ; close progn
  3516.  
  3517.                    
  3518.             ); close if
  3519.  
  3520.             ;* no extended entity data here
  3521.  
  3522.             (progn
  3523.             (setq ed
  3524.             (cons
  3525.             
  3526.             (list
  3527.                 -3
  3528.                 (list
  3529.                 "VIVID_RJH"
  3530.                 (cons 1000 "facet")
  3531.                 )
  3532.                             
  3533.             ); close list
  3534.  
  3535.             s
  3536.  
  3537.             ); close cons
  3538.             ); close setq
  3539.             (entmod ed)
  3540.  
  3541.             (setq temp1 (1+ temp1)) ; incr. counter
  3542.             ); close progn
  3543.  
  3544.         ) ; close if
  3545.  
  3546.         ); close if
  3547.  
  3548.         (setq temp (1+ temp)) ;increment index into ss
  3549.  
  3550.     ); close while
  3551.  
  3552.     ;* print statistics
  3553.  
  3554.     (princ "\n")
  3555.     (prin1 temp1)
  3556.     (princ " objects faceted.")
  3557.     (princ)
  3558.  
  3559.  
  3560.  
  3561. )
  3562.  
  3563. ;******************************************************************
  3564. ;*
  3565. ;* c:smooth?    AutoCAD command to enquire if a block or mesh is
  3566. ;*        smoothed or not.  Requires R11
  3567. ;*
  3568. ;*****************************************************************
  3569.  
  3570. (defun c:smooth? (/ temp )
  3571.  
  3572.     (setq s (entget (car (entsel)) (list "VIVID_RJH")))
  3573.     (setq temp nil)
  3574.  
  3575.     (if     (= (cdr (assoc 0 s)) "INSERT")    ;block
  3576.         (setq temp "block")
  3577.         
  3578.         (if    (and (= (cdr (assoc 0 s)) "POLYLINE") 
  3579.                  (or
  3580.              
  3581.                 (= 64 (boole 1 64 (cdr (assoc 70 s))))
  3582.                 (= 16 (boole 1 16 (cdr (assoc 70 s))))
  3583.                  )
  3584.             )
  3585.  
  3586.             (setq temp "mesh")
  3587.             (princ "\nEnitity is not a block or mesh.")
  3588.         )
  3589.     )
  3590.  
  3591.     (while    temp
  3592.  
  3593.         (if    (smooth_entity)
  3594.             (progn
  3595.                 (princ "\n")
  3596.                 (princ "Entity is a smoothed ")
  3597.                 (princ temp)    
  3598.             )
  3599.  
  3600.             (progn
  3601.                 (princ "\n")
  3602.                 (princ "Entity is a faceted ")
  3603.                 (princ temp)    
  3604.             )
  3605.         )
  3606.         (setq temp nil)
  3607.  
  3608.     ) ; close while
  3609. (princ)
  3610.  
  3611. )
  3612.  
  3613. ;;
  3614. ;; routine called by 2dpolyline handler-- steps through segment_list--
  3615. ;; a list of the polyline segments and their attributes produced by the
  3616. ;; preprocess_poly routine
  3617. ;;
  3618.  
  3619. (defun draw_poly ( trans_matrix / index1 )
  3620.  
  3621.     (setq index1 0)
  3622.     
  3623.  
  3624.     (setq prev_segment nil)
  3625.     (setq this_segment (nth index1 segment_list))
  3626.     (setq next_segment (nth (1+ index1) segment_list))
  3627.  
  3628.     ;; first element in segment list needs to be processed differently
  3629.     ;; if this is a closed list & segment is fat
  3630.  
  3631.     (if    (and    closed?
  3632.             next_segment
  3633.             (= (car this_segment) "fat" )
  3634.             (= (car (last segment_list)) "fat" )
  3635.             (not (equal (nth 3 this_segment) (nth 4 this_segment)))
  3636.             (not (equal (nth 5 (last segment_list)) (nth 6 (last segment_list))))
  3637.         )
  3638.  
  3639.         (progn 
  3640.         (setq save_next next_segment)
  3641.         (setq this_segment (last segment_list))
  3642.         (setq next_segment this_segment)
  3643.         (close_end trans_matrix)
  3644.         (setq this_segment next_segment next_segment save_next)
  3645.         )
  3646.  
  3647.         (if     (and    save_thickness
  3648.                 (= (car this_segment) "fat")
  3649.             )
  3650.             (draw_end (nth 3 this_segment) (nth 4 this_segment) trans_matrix)
  3651.         )
  3652.  
  3653.     )
  3654.  
  3655.  
  3656.     (while    this_segment
  3657.  
  3658.         ;** fat segment?
  3659.         (if    (equal (car this_segment) "fat")
  3660.  
  3661.             (progn
  3662.  
  3663.  
  3664.             ;*** check next segment to see if we need to close end
  3665.             (if    (and    next_segment
  3666.                     (= (car next_segment) "fat")
  3667.                     (not (equal (nth 5 this_segment) (nth 6 this_segment)))
  3668.                     (not (equal (nth 3 next_segment) (nth 4 next_segment)))
  3669.                 )
  3670.  
  3671.                 (close_end trans_matrix)
  3672.  
  3673.                 (if    save_thickness
  3674.                     (draw_end (nth 5 this_segment) (nth 6 this_segment) trans_matrix)
  3675.                 )
  3676.  
  3677.             )
  3678.  
  3679.  
  3680.             (draw_fat this_segment trans_matrix)
  3681.  
  3682.             ) ;close progn
  3683.  
  3684.  
  3685.             (if    (equal (car this_segment) "arc")
  3686.  
  3687.                 (draw_arc this_segment trans_matrix)
  3688.  
  3689.                 (if    save_thickness
  3690.                     (draw_skinny this_segment trans_matrix)
  3691.                 )
  3692.  
  3693.             )
  3694.  
  3695.         ); close if
  3696.  
  3697.         (setq index1 (1+ index1))
  3698.         (setq this_segment next_segment)
  3699.         (setq next_segment (nth (1+ index1) segment_list))
  3700.  
  3701.     )  ; close while
  3702.  
  3703. ) ; close defun
  3704.  
  3705.  
  3706. ;;
  3707. ;;  close_end  routine to close ends of fat polylines
  3708. ;;  results are written to global variables this_segment & next_segment
  3709. ;;
  3710.  
  3711. (defun close_end (trans_matrix / a b )                 
  3712.  
  3713.     ;* is difference in angles > .05 radians (~3 degrees)
  3714.  
  3715.     (if    (>     (abs 
  3716.                 (- 
  3717.  
  3718.                 (abs 
  3719.                 (- 
  3720.                 (angle (nth 1 this_segment) (nth 2 this_segment))
  3721.                 (/ pi 2.0)
  3722.                 ) 
  3723.                 )
  3724.  
  3725.                 (abs 
  3726.                 (- 
  3727.                 (angle (nth 1 next_segment) (nth 2 next_segment))
  3728.                 (/ pi 2.0)
  3729.                 ) 
  3730.                 )
  3731.                 
  3732.                 )
  3733.  
  3734.             )
  3735.  
  3736.             0.05
  3737.  
  3738.         )
  3739.  
  3740.                 
  3741.         ;close end here
  3742.  
  3743.         (progn
  3744.  
  3745.             (setq a    (inters
  3746.                 (nth 3 this_segment)
  3747.                 (nth 5 this_segment)
  3748.                 (nth 3 next_segment)
  3749.                 (nth 5 next_segment)
  3750.                 nil
  3751.                 )
  3752.             )
  3753.  
  3754.  
  3755.             (setq b    (inters
  3756.                 (nth 4 this_segment)
  3757.                 (nth 6 this_segment)
  3758.                 (nth 4 next_segment)
  3759.                 (nth 6 next_segment)
  3760.                 nil
  3761.                 )
  3762.             )
  3763.  
  3764.  
  3765.             (setq this_segment
  3766.  
  3767.                 (list
  3768.                 (car this_segment)
  3769.                 (cadr this_segment)
  3770.                 (caddr this_segment)
  3771.                 (cadddr this_segment)
  3772.                 (nth 4 this_segment)
  3773.                 a
  3774.                 b
  3775.                 )
  3776.             )
  3777.  
  3778.             (setq next_segment
  3779.  
  3780.                 (list
  3781.                 (car next_segment)
  3782.                 (cadr next_segment)
  3783.                 (caddr next_segment)
  3784.                 a
  3785.                 b
  3786.                 (nth 5 next_segment)
  3787.                 (nth 6 next_segment)
  3788.                 )
  3789.             )
  3790.  
  3791.             
  3792.         ) ; close progn
  3793.  
  3794.         ;; no need to close-- draw ends if thick
  3795.  
  3796.         (if    save_thickness
  3797.             
  3798.             (progn
  3799.             (draw_end (nth 5 this_segment) (nth 6 this_segment) trans_matrix)
  3800.             (draw_end (nth 3 next_segment) (nth 4 next_segment) trans_matrix)
  3801.             )
  3802.  
  3803.         )
  3804.  
  3805.     ) ; close if
  3806.  
  3807. ) ; close defun
  3808.  
  3809. ;;
  3810. ;;
  3811. ;;
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823. ;
  3824. ;
  3825. ;  
  3826.  
  3827. (defun draw_arc (segment1 trans_matrix / draw_this_arc?)
  3828.  
  3829.         (setq draw_this_arc? T)
  3830.  
  3831.  
  3832.  
  3833.         (if    (or
  3834.                 save_thickness
  3835.                 (nth 4 segment1)
  3836.  
  3837.             )
  3838.  
  3839.  
  3840.             (progn
  3841.  
  3842.                 (get_arc_params
  3843.  
  3844.                     (cadr segment1)
  3845.                     (caddr segment1)
  3846.                     (cadddr segment1)
  3847.  
  3848.                 )
  3849.  
  3850.                 ;** certain parameters can be translated now
  3851.  
  3852.  
  3853.                 (setq radius_len (* radius_len s_factor))
  3854.  
  3855.                 
  3856.                 (setq clip1_normal (trans clip1_normal save_extrude 0 T))
  3857.                 (setq clip2_normal (trans clip2_normal save_extrude 0 T))                
  3858.                 
  3859.                 (if    trans_matrix
  3860.                     (progn
  3861.                     (setq clip1_normal 
  3862.                                    (mapcar '-     
  3863.                                    (MCS_to_WCS clip1_normal trans_matrix)
  3864.                                    (MCS_to_WCS (list 0 0 0) trans_matrix)
  3865.                                )
  3866.                     )
  3867.                     (setq clip2_normal 
  3868.  
  3869.                                    (mapcar '-    
  3870.                                        (MCS_to_WCS clip2_normal trans_matrix)
  3871.                                        (MCS_to_WCS (list 0 0 0) trans_matrix)
  3872.                                    )
  3873.                     )
  3874.                     ); close progn
  3875.                 )
  3876.  
  3877.                 (setq s_arc_center
  3878.  
  3879.                     (real_to_string
  3880.  
  3881.                     (if     trans_matrix
  3882.                         (PROGN
  3883.                         (MCS_to_WCS     (trans
  3884.                                 arc_center
  3885.                                 save_extrude
  3886.                                 0
  3887.                                 )
  3888.                                 trans_matrix
  3889.                         )
  3890.                         )
  3891.  
  3892.                         (trans arc_center save_extrude 0)
  3893.  
  3894.                     ) ; close if
  3895.  
  3896.                     ) ; close real_to_string
  3897.  
  3898.                 ) ; close setq
  3899.  
  3900.     
  3901.                 (setq s_clip1 
  3902.                     (strcat "clip { center "
  3903.                     s_arc_center
  3904.                     " normal "
  3905.                     (real_to_string clip1_normal)
  3906.                     "}"
  3907.                     )
  3908.                 )
  3909.         
  3910.                 (setq s_clip2 
  3911.                     (strcat "clip { center "
  3912.                     s_arc_center
  3913.                     " normal "
  3914.                     (real_to_string clip2_normal)
  3915.                     "}"
  3916.                     )
  3917.                 )
  3918.  
  3919.  
  3920.  
  3921.             ) ; close progn
  3922.  
  3923.  
  3924.         
  3925.             (setq draw_this_arc? nil) 
  3926.  
  3927.         ) ; close if
  3928.  
  3929.  
  3930.     (while    draw_this_arc?
  3931.  
  3932.  
  3933.         (if    (and (setq width (nth 4 segment1))
  3934.                  (/= 0 width)
  3935.             )             ; wide arc?
  3936.  
  3937.             (progn
  3938.             (setq radius1 (-  radius_len (/ (* width s_factor) 2.0)))
  3939.             (setq radius2 (+ radius_len (/ (* width s_factor) 2.0)))
  3940.  
  3941.             (if    trans_matrix
  3942.  
  3943.                 (setq normal1    
  3944.                         (mapcar '-
  3945.                         (MCS_to_WCS save_extrude trans_matrix)
  3946.                         (MCS_to_WCS '(0 0 0) trans_matrix)
  3947.                         )
  3948.                 )
  3949.  
  3950.                 (setq normal1 save_extrude)
  3951.             )
  3952.  
  3953.  
  3954.             (if    save_thickness
  3955.  
  3956.                     
  3957.                 (progn
  3958.                 
  3959.                 ;; wide and thick arc here
  3960.     
  3961.                 ;; calculate and draw end rectangles
  3962.  
  3963.  
  3964.                 (setq v1 (cadr segment1))
  3965.                 (setq v2 (caddr segment1))
  3966.                 (setq v3    (list
  3967.  
  3968.                         (+
  3969.                         (car v1)
  3970.                         (-    (cadr arc_center)
  3971.                             (cadr v1)
  3972.                         )
  3973.                         )
  3974.  
  3975.                         (+
  3976.                         (cadr v1)
  3977.                         (- (-    (car arc_center)
  3978.                             (car v1)
  3979.                         ))
  3980.                         )
  3981.                         
  3982.                         (caddr v1)
  3983.  
  3984.                         ) ; close list
  3985.  
  3986.                 ) ;close setq
  3987.  
  3988.                 (setq v4    (list
  3989.  
  3990.                         (+
  3991.                         (car v2)
  3992.                         (-    (cadr arc_center)
  3993.                             (cadr v2)
  3994.                         )
  3995.                         )
  3996.  
  3997.                         (+
  3998.                         (cadr v2)
  3999.                         (-(-    (car arc_center)
  4000.                             (car v2)
  4001.                         ))
  4002.                         )
  4003.                         
  4004.                         (caddr v2)
  4005.  
  4006.                         ) ; close list
  4007.  
  4008.                 ) ;close setq
  4009.  
  4010.                     
  4011.     
  4012.                 (setq temp (derive_wide v1 v3 width))
  4013.                 (setq a (car temp))
  4014.                 (setq a1    (list
  4015.                         (car a)
  4016.                         (cadr a)
  4017.                         (+ (caddr a) save_thickness)
  4018.                         )
  4019.                 )
  4020.                 (setq b (cadr temp))
  4021.                 (setq b1    (list
  4022.                         (car b)
  4023.                         (cadr b)
  4024.                         (+ (caddr b) save_thickness)
  4025.                         )
  4026.                 )
  4027.  
  4028.                 (setq a (trans a save_extrude 0))
  4029.                 (setq a1 (trans a1 save_extrude 0))
  4030.                 (setq b (trans b save_extrude 0))
  4031.                 (setq b1 (trans b1 save_extrude 0))
  4032.                 
  4033.  
  4034.     
  4035.     
  4036.                 (setq temp (derive_wide v2 v4 width))
  4037.  
  4038.                 (setq c (car temp))
  4039.                 (setq c1    (list
  4040.                         (car c)
  4041.                         (cadr c)
  4042.                         (+ (caddr c) save_thickness)
  4043.                         )
  4044.                 )
  4045.                 (setq d (cadr temp))
  4046.                 (setq d1    (list
  4047.                         (car d)
  4048.                         (cadr d)
  4049.                         (+ (caddr d) save_thickness)
  4050.                         )
  4051.                 )
  4052.  
  4053.                 (setq c (trans c save_extrude 0))
  4054.                 (setq c1 (trans c1 save_extrude 0))
  4055.                 (setq d (trans d save_extrude 0))
  4056.                 (setq d1 (trans d1 save_extrude 0))
  4057.                 
  4058.  
  4059.  
  4060.     
  4061.                 (draw_4 a b b1 a1 trans_matrix)
  4062.                 (draw_4 d c c1 d1 trans_matrix)
  4063.  
  4064.     
  4065.                 (setq arc_center2 
  4066.  
  4067.                     (list
  4068.                     (car arc_center)
  4069.                     (cadr arc_center)
  4070.                     (+ (caddr arc_center) save_thickness)
  4071.                     )
  4072.                 )
  4073.                 
  4074.                 (if    trans_matrix
  4075.  
  4076.                     (setq arc_center2
  4077.                     (MCS_to_WCS
  4078.                     (trans arc_center2 save_extrude 0)
  4079.                     trans_matrix)
  4080.                     )
  4081.  
  4082.                     (setq arc_center2
  4083.                     (trans arc_center2 save_extrude 0)
  4084.                     )
  4085.                         
  4086.                 )
  4087.     
  4088.                 ;** save some strings for output
  4089.     
  4090.                 (setq s_arc_center2 (real_to_string arc_center2))
  4091.             
  4092.                 
  4093.                 
  4094.                 (setq new
  4095.     
  4096.                     (cons 
  4097.     
  4098.                     (car old)
  4099.     
  4100.                     (list
  4101.                     (append
  4102.  
  4103.                     (cadr old)
  4104.     
  4105.  
  4106.     
  4107.                     (list
  4108.  
  4109.                     ;* first ring
  4110.                     (strcat
  4111.                     "ring { center "
  4112.                     s_arc_center
  4113.                     )
  4114.     
  4115.                     (strcat "normal "
  4116.                     (real_to_string normal1 )
  4117.                     )
  4118.     
  4119.                     (strcat "min_radius "
  4120.                     (rtos radius1 2 6)
  4121.                     )
  4122.     
  4123.                     (strcat "max_radius "
  4124.                     (rtos radius2 2 6)
  4125.                     )
  4126.     
  4127.                     s_clip1
  4128.     
  4129.                     s_clip2
  4130.     
  4131.                     "}"
  4132.     
  4133.  
  4134.     
  4135.                     ;*  second ring        
  4136.  
  4137.                     (strcat
  4138.                     "ring { center "
  4139.                     s_arc_center2
  4140.                     )
  4141.     
  4142.                     (strcat "normal "
  4143.                     (real_to_string normal1)
  4144.                     )
  4145.     
  4146.                     (strcat "min_radius "
  4147.                     (rtos radius1 2 6)
  4148.                     )
  4149.     
  4150.                     (strcat "max_radius "
  4151.                     (rtos radius2 2 6)
  4152.                     )
  4153.     
  4154.                     s_clip1
  4155.     
  4156.                     s_clip2
  4157.     
  4158.                     "}"
  4159.     
  4160.                     ;* first cone
  4161.     
  4162.  
  4163.                     (strcat
  4164.                     "cone { base "
  4165.                     s_arc_center
  4166.                     )
  4167.     
  4168.                     (strcat
  4169.                     "apex "
  4170.                     s_arc_center2
  4171.                     )
  4172.     
  4173.     
  4174.                     (strcat "base_radius "
  4175.                     (rtos radius1 2 6)
  4176.                     )
  4177.     
  4178.                     (strcat "apex_radius "
  4179.                     (rtos radius1 2 6)
  4180.                     )
  4181.     
  4182.                     s_clip1
  4183.     
  4184.                     s_clip2
  4185.     
  4186.                     "}"
  4187.     
  4188.                     ;*  second cone                
  4189.                     (strcat
  4190.                     "cone { base "
  4191.                     s_arc_center
  4192.                     )
  4193.     
  4194.                     (strcat "apex "
  4195.                     s_arc_center2
  4196.                     )
  4197.     
  4198.     
  4199.                     (strcat "base_radius "
  4200.                     (rtos radius2 2 6)
  4201.                     )
  4202.     
  4203.                     (strcat "apex_radius "
  4204.                     (rtos radius2 2 6)
  4205.                     )
  4206.     
  4207.                     s_clip1
  4208.     
  4209.                     s_clip2
  4210.     
  4211.                     "}"
  4212.     
  4213.                     ) ;close list
  4214.                     ) ;close append
  4215.                     ) ;close list
  4216.                     ) ;close cons
  4217.     
  4218.                 ) ;close setq
  4219.     
  4220.                 (setq master (subst new old master))
  4221.                 (setq old new)
  4222.  
  4223.                 (setq draw_this_arc? nil)
  4224.  
  4225.                 (setq 2dpoly_p_count (+ 2 2dpoly_p_count))
  4226.                 (setq 2dpoly_c_count (+ 2 2dpoly_c_count))
  4227.                 (setq 2dpoly_r_count (+ 2 2dpoly_r_count))
  4228.                 
  4229.                 
  4230.                 ) ; close progn
  4231.  
  4232.  
  4233. ;;;;;;;** draw fat flat arc here
  4234.  
  4235.  
  4236.                 (progn
  4237.                     
  4238.                 (setq new
  4239.     
  4240.                     (cons 
  4241.     
  4242.                     (car old)
  4243.     
  4244.                     (list
  4245.                     (append
  4246.  
  4247.                     (cadr old)
  4248.     
  4249.  
  4250.     
  4251.                     (list
  4252.  
  4253.                     ;* first ring
  4254.                     (strcat
  4255.                     "ring { center "
  4256.                     s_arc_center
  4257.                     )
  4258.     
  4259.                     (strcat "normal "
  4260.                     (real_to_string normal1 )
  4261.                     )
  4262.     
  4263.                     (strcat "min_radius "
  4264.                     (rtos radius1 2 6)
  4265.                     )
  4266.     
  4267.                     (strcat "max_radius "
  4268.                     (rtos radius2 2 6)
  4269.                     )
  4270.     
  4271.                     s_clip1
  4272.     
  4273.                     s_clip2
  4274.     
  4275.                     "}"
  4276.     
  4277.  
  4278.     
  4279.     
  4280.                         
  4281.                     ) ;close list
  4282.                     ) ;close append
  4283.                     ) ;close list
  4284.                     ) ;close cons
  4285.     
  4286.                 ) ;close setq
  4287.     
  4288.                 (setq master (subst new old master))
  4289.                 (setq old new)
  4290.  
  4291.                 (setq draw_this_arc? nil)
  4292.  
  4293.                 (setq 2dpoly_r_count (1+ 2dpoly_r_count))
  4294.                 
  4295.                 
  4296.                 ) ; close progn
  4297.                 )
  4298.  
  4299.             ) ; close if
  4300.  
  4301.                 
  4302.  
  4303.  
  4304. ;;;;** draw extruded skinny arc here
  4305.  
  4306.  
  4307.             (progn    
  4308.  
  4309.                 ;; need extruded center
  4310.  
  4311.                 (setq arc_center_2 
  4312.                 (list
  4313.                 (car arc_center)
  4314.                 (cadr arc_center)
  4315.                 (+ (caddr arc_center save_thickness))
  4316.                 )
  4317.                 )
  4318.  
  4319.                 (setq arc_center_2 (trans arc_center_2 save_extrude 0))
  4320.                 
  4321.                 (if    trans_matrix
  4322.                     (setq arc_center_2 (MCS_to_WCS arc_center_2 trans_matrix))
  4323.                 )
  4324.  
  4325.         
  4326.                 (setq new
  4327.         
  4328.                     (cons 
  4329.         
  4330.                     (car old)
  4331.         
  4332.                     (list
  4333.                     (append
  4334.         
  4335.                     (cadr old)
  4336.  
  4337.  
  4338.         
  4339.                     (list
  4340.         
  4341.         
  4342.                     ;* first cone
  4343.  
  4344.         
  4345.                     (strcat
  4346.                     "cone { base "
  4347.                     s_arc_center
  4348.                     )
  4349.         
  4350.                     (strcat "apex "
  4351.                     (real_to_string arc_center_2)
  4352.                     )
  4353.  
  4354.         
  4355.                     (strcat "base_radius "
  4356.                     (rtos radius_len 2 6)
  4357.                     )
  4358.         
  4359.                     (strcat "apex_radius "
  4360.                     (rtos radius_len 2 6)
  4361.                     )
  4362.         
  4363.                     s_clip1
  4364.         
  4365.                     s_clip2
  4366.         
  4367.                     "}"
  4368.         
  4369.         
  4370.                     ) ;close list
  4371.                     ) ;close append
  4372.                     ) ;close list
  4373.                     ) ;close cons
  4374.         
  4375.                 ) ;close setq
  4376.         
  4377.                 (setq master (subst new old master))
  4378.                 (setq old new)
  4379.  
  4380.  
  4381.                 (setq draw_this_arc? nil)
  4382.                 (setq 2dpoly_c_count (1+ 2dpoly_c_count))
  4383.  
  4384.                 
  4385.         
  4386.             ) ; close progn
  4387.  
  4388.         ) ; close if
  4389.  
  4390.     ); close while
  4391.  
  4392. ); close defun
  4393.  
  4394.                 
  4395.  
  4396.  
  4397. ;;
  4398. ;;  get_arc_params -- called by draw_arc 
  4399. ;;
  4400. ;;  input--  two vertices and a bulge (1/4 tangent of included angle)
  4401. ;;
  4402. ;;  finds results of global variables as follows:
  4403. ;;
  4404. ;;  radius_len -- length of radius
  4405. ;;  len_ratio -- ratio of segment length to radius 
  4406. ;;  clip1_normal -- normal of 1st clipping plane
  4407. ;;  clip2_normal -- normal of 2nd clipping plane
  4408.  
  4409.  
  4410.  
  4411.  
  4412. (defun get_arc_params ( v1 v2 bulge / a b m r)
  4413.  
  4414.     (setq theta (* 2.0 (atan bulge)))
  4415.     (setq a (/ (distance v1 v2) 2.0))
  4416.     (setq r (/ a (sin theta) ))
  4417.     (setq radius_len (abs r))
  4418.     (setq sign_r (/ r radius_len))
  4419.     (setq b (* radius_len (cos theta)))
  4420.     (setq len_ratio (/ b a))
  4421.  
  4422.     (setq delta_x (- (car v2) (car v1)))
  4423.     (setq delta_y (- (cadr v2) (cadr v1)))
  4424.  
  4425.     (setq m        (list
  4426.             (+ (car v1) (/ delta_x 2.0))
  4427.             (+ (cadr v1) (/ delta_y 2.0))
  4428.             (caddr v1)
  4429.             )
  4430.     )
  4431.  
  4432.     (setq arc_center     (list
  4433.                 (+ (car m) (* (/ delta_y  2.0) (- sign_r) len_ratio))
  4434.                 (+ (cadr m) (* (/ (- delta_x) 2.0) (- sign_r) len_ratio))
  4435.                 (caddr m)
  4436.                 )
  4437.     )
  4438.  
  4439. ;    (if     (> (car v1) (car v2))
  4440. ;        (progn
  4441. ;        (setq v3 v2)
  4442. ;        (setq v2 v1)
  4443. ;        (setq v1 v3)
  4444. ;        )
  4445. ;    )
  4446.  
  4447.  
  4448.     (setq delta_x_clip1 (if        (> 0 bulge)
  4449.                     (- (car arc_center) (car v2))
  4450.                     (- (car v2) (car arc_center))
  4451.                  )
  4452.     )
  4453.  
  4454.     (setq delta_y_clip1 (if        (> 0 bulge)
  4455.                     (- (cadr arc_center) (cadr v2))
  4456.                     (- (cadr v2) (cadr arc_center))
  4457.                 )
  4458.  
  4459.     )
  4460.  
  4461.     (setq m_clip1     (list
  4462.             (+ (car v2) (/ delta_x_clip1 2.0))
  4463.             (+ (cadr v2) (/ delta_y_clip1 2.0))
  4464.             (caddr v2)
  4465.             )
  4466.     )
  4467.  
  4468.     (setq e_clip1    (list
  4469.             (+ (car m_clip1)  delta_y_clip1)
  4470.             (+ (cadr m_clip1) (- delta_x_clip1))
  4471.             (caddr m_clip1)
  4472.             )
  4473.     )
  4474.  
  4475.     (setq clip1_normal    (list
  4476.                 (- (car e_clip1) (car m_clip1))
  4477.                 (- (cadr e_clip1) (cadr m_clip1))
  4478.                 0.0
  4479.                 )
  4480.     )
  4481.  
  4482.  
  4483.  
  4484.  
  4485.  
  4486.  
  4487.     (setq delta_x_clip2 (if     (> 0 bulge)
  4488.                     (- (car arc_center) (car v1))
  4489.                     (- (car v1) (car arc_center))
  4490.                 )
  4491.     )
  4492.  
  4493.     (setq delta_y_clip2 (if        (> 0 bulge)
  4494.                     (- (cadr arc_center) (cadr v1))
  4495.                     (- (cadr v1) (cadr arc_center))
  4496.                 )
  4497.     )
  4498.  
  4499.     (setq m_clip2     (list
  4500.             (+ (car v1) (/ delta_x_clip2 2.0))
  4501.             (+ (cadr v1) (/ delta_y_clip2 2.0))
  4502.             (caddr v1)
  4503.             )
  4504.     )
  4505.  
  4506.     (setq e_clip2    (list
  4507.             (+ (car m_clip2)  (- delta_y_clip2))
  4508.             (+ (cadr m_clip2)  delta_x_clip2)
  4509.             (caddr m_clip2)
  4510.             )
  4511.     )
  4512.  
  4513.     (setq clip2_normal    (list
  4514.                 (- (car e_clip2) (car m_clip2))
  4515.                 (- (cadr e_clip2) (cadr m_clip2))
  4516.                 0.0
  4517.                 )
  4518.     )
  4519.  
  4520.  
  4521. )
  4522.  
  4523.  
  4524. (defun draw_skinny (segment1 trans_matrix / a1 b1)
  4525.  
  4526.     (setq a1    
  4527.             (trans
  4528.             (list
  4529.             (car (cadr segment1))
  4530.             (cadr (cadr segment1))
  4531.             (+ (caddr (cadr segment1)) save_thickness)
  4532.             )
  4533.             save_extrude
  4534.             0
  4535.             )
  4536.     )
  4537.  
  4538.     (setq b1    
  4539.             (trans
  4540.             (list
  4541.             (car (caddr segment1))
  4542.             (cadr (caddr segment1))
  4543.             (+ (caddr (caddr segment1)) save_thickness)
  4544.             )
  4545.             save_extrude
  4546.             0
  4547.             )
  4548.     )
  4549.  
  4550.     (setq a (trans (cadr segment1) save_extrude 0))
  4551.     (setq b (trans (caddr segment1) save_extrude 0))
  4552.  
  4553.  
  4554.  
  4555.     (draw_4 a b b1 a1 trans_matrix)
  4556.     (setq 2dpoly_p_count (1+ 2dpoly_p_count))
  4557.  
  4558. )    
  4559.  
  4560.  
  4561. (defun draw_fat (segment1 trans_matrix / a1 b1 c1 d1 )
  4562.  
  4563.     (if    save_thickness
  4564.  
  4565.         ;; thick and fat
  4566.  
  4567.         (progn
  4568.  
  4569.         (setq a1    
  4570.                 (trans
  4571.                 (list
  4572.                 (car (nth 3 segment1))
  4573.                 (cadr (nth 3 segment1))
  4574.                 (+ (caddr (nth 3 segment1)) save_thickness)
  4575.                 )
  4576.                 save_extrude
  4577.                 0
  4578.                 )
  4579.         )
  4580.  
  4581.         (setq b1    
  4582.                 (trans
  4583.                 (list
  4584.                 (car (nth 4 segment1))
  4585.                 (cadr (nth 4 segment1))
  4586.                 (+ (caddr (nth 4 segment1)) save_thickness)
  4587.                 )
  4588.                 save_extrude
  4589.                 0
  4590.                 )
  4591.         )
  4592.         (setq c1    
  4593.                 (trans
  4594.                 (list
  4595.                 (car (nth 5 segment1))
  4596.                 (cadr (nth 5 segment1))
  4597.                 (+ (caddr (nth 5 segment1)) save_thickness)
  4598.                 )
  4599.                 save_extrude
  4600.                 0
  4601.                 )
  4602.         )
  4603.  
  4604.  
  4605.         (setq d1    
  4606.                 (trans
  4607.                 (list
  4608.                 (car (nth 6 segment1))
  4609.                 (cadr (nth 6 segment1))
  4610.                 (+ (caddr (nth 6 segment1)) save_thickness)
  4611.                 )
  4612.                 save_extrude
  4613.                 0
  4614.                 )
  4615.         )
  4616.  
  4617.  
  4618.  
  4619.         (setq a (trans (nth 3 segment1) save_extrude 0))
  4620.         (setq b (trans (nth 4 segment1) save_extrude 0))
  4621.         (setq c (trans (nth 5 segment1) save_extrude 0))
  4622.         (setq d (trans (nth 6 segment1) save_extrude 0))
  4623.  
  4624.  
  4625.  
  4626.         (draw_4 a b d c trans_matrix)
  4627.         (draw_4 a1 b1 d1 c1 trans_matrix)
  4628.         (draw_4 a c c1 a1 trans_matrix)
  4629.         (draw_4 b d d1 b1 trans_matrix)
  4630.  
  4631.         (setq 2dpoly_p_count (+ 2dpoly_p_count 4))
  4632.  
  4633.  
  4634.         ) ;close progn
  4635.  
  4636.  
  4637.         ;; just fat -- trivial
  4638.  
  4639.         (progn
  4640.  
  4641.         (draw_4 
  4642.             (trans (nth 3 segment1) save_extrude 0)
  4643.             (trans (nth 4 segment1) save_extrude 0)
  4644.             (trans (nth 6 segment1) save_extrude 0)
  4645.             (trans (nth 5 segment1) save_extrude 0)
  4646.             trans_matrix
  4647.         )
  4648.  
  4649.         (setq 2dpoly_p_count (1+ 2dpoly_p_count))
  4650.  
  4651.         ) ; close progn
  4652.  
  4653.     ) ; close if
  4654.  
  4655. ) ; close draw_fat
  4656.  
  4657.  
  4658. (defun draw_end (a b trans_matrix / a1 b1)
  4659.  
  4660.         (setq a1    
  4661.                 (trans
  4662.                 (list
  4663.                 (car a)
  4664.                 (cadr a)
  4665.                 (+ (caddr a) save_thickness)
  4666.                 )
  4667.                 save_extrude
  4668.                 0
  4669.                 )
  4670.         )
  4671.  
  4672.  
  4673.  
  4674.         (setq b1    
  4675.                 (trans
  4676.                 (list
  4677.                 (car b)
  4678.                 (cadr b)
  4679.                 (+ (caddr b) save_thickness)
  4680.                 )
  4681.                 save_extrude
  4682.                 0
  4683.                 )
  4684.         )
  4685.  
  4686.         (setq a (trans a save_extrude 0))
  4687.         (setq b (trans b save_extrude 0))
  4688.  
  4689.  
  4690.         (draw_4 a b b1 a1 trans_matrix)
  4691.  
  4692.         (setq 2dpoly_p_count (1+ 2dpoly_p_count))
  4693.  
  4694. ) ; close draw_end
  4695.  
  4696. ;;
  4697. ;;
  4698. ;;  derive_wide
  4699.  
  4700.  
  4701.  
  4702. (defun derive_wide (v1 v2 width / seg_len delta_x delta_y)
  4703.     
  4704.     (setq len_ratio (/ (/ width 2.0) (distance v1 v2)))
  4705.     (setq delta_x (- (car v2) (car v1)))
  4706.     (setq delta_y (- (cadr v2) (cadr v1)))
  4707.  
  4708.     (list
  4709.         (list
  4710.  
  4711.         (+ (car v1) (* (- delta_y) len_ratio))
  4712.         (+ (cadr v1) (* delta_x len_ratio))
  4713.         (caddr v1)
  4714.  
  4715.         )
  4716.  
  4717.         (list
  4718.  
  4719.         (+ (car v1) (*  delta_y len_ratio))
  4720.         (+ (cadr v1) (* (- delta_x) len_ratio))
  4721.         (caddr v1)
  4722.  
  4723.         )
  4724.  
  4725.     )
  4726.  
  4727. )
  4728.  
  4729.  
  4730.  
  4731. (defun pre_process_poly ( / this_vertex next_vertex)
  4732.  
  4733.  
  4734.     (setq segment_list nil)
  4735.  
  4736.     (if    (= (boole 1 1 (cdr (assoc 70 s))) 1)    ;close polyline?
  4737.         (setq closed_poly? T)
  4738.         (setq closed_poly? nil)
  4739.     )        
  4740.  
  4741.     (setq save_extrude (cdr (assoc 210 s)))
  4742.  
  4743.     (setq e (entnext e))
  4744.     (setq s (entget e (list "VIVID_RJH")))
  4745.  
  4746.  
  4747.     ;* save in case polyline is closed
  4748.     (setq first_vertex s)
  4749.  
  4750.     (setq this_vertex s)
  4751.     (setq e (entnext e))
  4752.     (setq s (entget e (list "VIVID_RJH")))                
  4753.     (setq next_vertex s)
  4754.  
  4755.  
  4756.     (while 
  4757.         (/= (cdr (assoc 0 s)) "SEQEND")
  4758.  
  4759.         (if    (not (equal (cdr (assoc 10 this_vertex)) (cdr (assoc 10 next_vertex)) ))
  4760.  
  4761.             (prep_poly this_vertex next_vertex)
  4762.         )
  4763.     
  4764.         (setq this_vertex s)
  4765.         (setq e (entnext e))
  4766.         (setq s (entget e (list "VIVID_RJH")))
  4767.         (setq next_vertex s)
  4768.  
  4769.  
  4770.     );  close while
  4771.  
  4772.     (if    closed_poly?
  4773.  
  4774.         (if    (not (equal (cdr (assoc 10 this_vertex)) (cdr (assoc 10 first_vertex)) ))
  4775.  
  4776.             (prep_poly this_vertex first_vertex)
  4777.         )
  4778.  
  4779.  
  4780.     )
  4781.  
  4782. )
  4783.  
  4784.  
  4785.  
  4786.  
  4787. (defun prep_poly ( this_vertex next_vertex / start_width end_width bulge temp a b c d)
  4788.  
  4789.     (setq start_width (cdr (assoc 40 this_vertex)))
  4790.     (setq end_width (cdr (assoc 41 this_vertex)))
  4791.  
  4792.     (if    (or    (/=  start_width 0)
  4793.                (/=  end_width 0)
  4794.         )
  4795.  
  4796.         ;; wide polyline here -- need to draw
  4797.  
  4798.         (setq draw_this_poly? T)
  4799.  
  4800.     )
  4801.  
  4802.  
  4803.     (if     (/= (setq bulge (cdr (assoc 42 this_vertex))) 0)
  4804.  
  4805.         ;* arc here
  4806.  
  4807.         ;* if arc is greater than 180 degrees, it needs to be split
  4808.         ;* into to arcs
  4809.  
  4810.         (if    (<= (abs bulge) 1.0)
  4811.             (progn
  4812.  
  4813.             (setq segment_list
  4814.             (append
  4815.             segment_list
  4816.             (list
  4817.             (list
  4818.             "arc"
  4819.             (cdr (assoc 10 this_vertex))
  4820.             (cdr (assoc 10 next_vertex))
  4821.             bulge
  4822.             start_width
  4823.             ) ; close list
  4824.             ) ; close list
  4825.             ) ; close append
  4826.             ) ; close setq
  4827.             ) ; close progn
  4828.  
  4829.  
  4830.             (progn
  4831.  
  4832.             (get_arc_params    (cdr (assoc 10 this_vertex))
  4833.                     (cdr (assoc 10 next_vertex))
  4834.                     bulge
  4835.             )
  4836.  
  4837.             (setq v3    (list
  4838.                     (+ (car (cdr (assoc 10 this_vertex)))
  4839.                        (* (- (car arc_center) (car (cdr (assoc 10 this_vertex))))
  4840.                           2.0
  4841.                         )
  4842.                     )
  4843.  
  4844.                     (+ (cadr (cdr (assoc 10 this_vertex)))
  4845.                        (* (- (cadr arc_center) (cadr (cdr (assoc 10 this_vertex))))
  4846.                           2.0
  4847.                         )
  4848.                     )
  4849.  
  4850.                     (caddr (cdr (assoc 10 this_vertex)))
  4851.  
  4852.                     ) ;close list
  4853.             ) ;close setq
  4854.  
  4855.             (setq theta (atan bulge))
  4856.  
  4857.             (if    (< bulge 0 )
  4858.                 (setq theta (+ theta (/ pi 4.0)))
  4859.                 (setq theta (- theta (/ pi 4.0)))
  4860.             )
  4861.  
  4862.             (setq bulge (tan theta))
  4863.  
  4864.  
  4865.  
  4866.             (setq segment_list
  4867.             (append
  4868.             segment_list
  4869.  
  4870.  
  4871.             (list
  4872.             (list
  4873.             "arc"
  4874.             (cdr (assoc 10 this_vertex))
  4875.             v3
  4876.             (/ bulge (abs bulge))
  4877.             start_width
  4878.             ) ; close list
  4879.             ) ; close list
  4880.  
  4881.             (list
  4882.             (list
  4883.             "arc"
  4884.             v3
  4885.             (cdr (assoc 10 next_vertex))
  4886.             bulge
  4887.             start_width
  4888.             ) ; close list
  4889.             ) ; close list
  4890.  
  4891.  
  4892.  
  4893.  
  4894.             ) ; close append
  4895.             ) ; close setq
  4896.             ) ; close progn
  4897.  
  4898.         ); close if
  4899.  
  4900.         ;* segment here- either fat or skinny
  4901.  
  4902.  
  4903.         (if    (or    (/= start_width 0)
  4904.                 (/= end_width 0)
  4905.             )
  4906.  
  4907.             (progn
  4908.  
  4909.             ;** wide segment
  4910.  
  4911.             (setq temp     (derive_wide
  4912.                     (cdr (assoc 10 this_vertex ))
  4913.                     (cdr (assoc 10 next_vertex ))
  4914.                     start_width)
  4915.             )
  4916.             (setq a (car temp))
  4917.             (setq b (cadr temp))
  4918.  
  4919.             (setq temp     (derive_wide 
  4920.                     (cdr (assoc 10 next_vertex ))
  4921.                     (cdr (assoc 10 this_vertex ))
  4922.                     end_width)
  4923.             )
  4924.             (setq d (car temp))
  4925.             (setq c (cadr temp))
  4926.  
  4927.  
  4928.             (setq segment_list
  4929.             (append
  4930.             segment_list
  4931.             (list
  4932.             (list
  4933.             "fat"
  4934.             (cdr (assoc 10 this_vertex))
  4935.             (cdr (assoc 10 next_vertex))
  4936.             a
  4937.             b
  4938.             c
  4939.             d
  4940.             )
  4941.             )
  4942.             )
  4943.             )
  4944.  
  4945.             ) ; close progn
  4946.                 
  4947.  
  4948.             ;** skinny segment
  4949.  
  4950.             (setq segment_list
  4951.             (append
  4952.             segment_list
  4953.             (list
  4954.             (list
  4955.             "skinny"
  4956.             (cdr (assoc 10 this_vertex))
  4957.             (cdr (assoc 10 next_vertex))
  4958.             )
  4959.             )
  4960.             )
  4961.             )
  4962.  
  4963.  
  4964.  
  4965.         ) ; close if
  4966.  
  4967.     ) ; close if
  4968.  
  4969. ) ; close prep_poly
  4970.  
  4971.  
  4972. (princ "loaded")        
  4973. (princ)
  4974.